Note that there are some explanatory texts on larger screens.

plurals
  1. POchrome extension message passing no response
    primarykey
    data
    text
    <p>I'm working on a pretty simple browser extension, but can't get the message passing to work: I can send messages, but the response is never delivered!</p> <p>My code: Its mostly just a copy from the browserActions tutorial, contentscripts tutorial (manifest) and message-passing api definition. </p> <p>manifest.json:</p> <pre><code>{ "manifest_version":2, "name": "FUN SCRIPT", "version": "1", "description": "THIS IS SOME FUN SCRIPT", "browser_action": { "name": "Fun", "icons": ["icon.png"], "default_icon": "icon.png", "default_popup": "popup.html" }, "content_scripts": [ { "js": [ "jquery.js", "background.js" ], "matches": [ "http://*/*", "https://*/*"] }], } </code></pre> <p>background.js</p> <pre><code>chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { console.log(sender.tab ? "from a content script:" + sender.tab.url : "from the extension"); if (request.greeting == "hello") sendResponse({farewell: "goodbye"}); }); </code></pre> <p>popup.js</p> <pre><code>document.addEventListener('DOMContentLoaded', function () { chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) { console.log(response.farewell); }); }); }); </code></pre> <p>popup.html</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Getting Started Extension's Popup&lt;/title&gt; &lt;style&gt; body { min-width: 357px; overflow-x: hidden; } img { margin: 5px; border: 2px solid black; vertical-align: middle; width: 75px; height: 75px; } &lt;/style&gt; &lt;script src="popup.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload