Ich kann keine Daten aus Chrome-Erweiterung Hintergrundskript mit XMLHTTPREQUEST senden, ich habe laufen und wampserver laufen, habe ich auch versucht, externe Links wie Google.XMLHTTPREQUEST Chrome-Erweiterung funktioniert nicht
Was ist zu tun:
User enters a permission defined tab, background script waits for hot key,when pressed a content_script is launched and generates a string, the string is sent back to the background script, then the background script should receive the string and send it to a php file, the php file should print hello, its made simple just to try see where is the problem, later php will have more code.
But its completely not working!
UPDATE
I tried to pack the extension then run it by drag and drop, it doesn't launch php script.
I tried to uninstall chrome, restart and then install it again but with no luck.
I have also allowed --allow-file-access-from-files
UPDATE 2
I am receiving the following error in debug mode:
extensions::sendRequest:41: Uncaught TypeError: Cannot read property 'callback' of undefined{TypeError: Cannot read property 'callback' of undefined
M anifest.json
{
"manifest_version": 2,
"name": "Extractor",
"version": "1",
"description": "Extract from 144",
"icons": { "16": "logo16.png",
"48": "logo48.png",
"128": "logo128.png" },
"page_action": {
"default_icon": {
"16": "logo16.png",
"48": "logo48.png",
"128": "logo128.png"
},
"default_title": "Extractor"
},
"background": {
"scripts": ["background.js"],
"persistent": true
},
"content_scripts": [
{
"matches" : ["https://www.msn.com/*"],
"js" : ["content_script.js"]
}
],
"permissions": [
"tabs",
"https://www.msn.com/*",
"activeTab",
"http://localhost/*"
],
"commands": {
"toggle-feature": {
"suggested_key": {
"default": "Ctrl+Shift+1",
"windows": "Ctrl+Shift+2"
},
"description": "Extract now"
}
} ,
"web_accessible_resources": ["content_script.js"]
}
Background.js
chrome.commands.onCommand.addListener(function(command) {
if (command === "toggle-feature") {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
for(var i = 0; i<tabs.length;i++) {
chrome.tabs.executeScript(tabs[i].id, {"file": "content_script.js"});
}
});
}
});
chrome.runtime.onMessage.addListener(
function(message, sender, sendResponse) {
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "http://localhost/test/test.php");
xhttp.send(message.url);
});
content_script.js
var url = 'this is just test' ;
chrome.runtime.sendMessage({ 'url' : url });
test.php
echo "hello";
Ich habe Berechtigungen hinzugefügt: 'http: // localhost/*'. (ohne Leerzeichen) – user7403949
hinzugefügt Warnung funktioniert, aber die PHP-Datei nicht os Ich denke, es gibt ein Problem mit xmlhttprequest – user7403949
Hallo, bitte bieten Sie Hilfe als Frage wurde aktualisiert. – user7403949