Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active December 16, 2017 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twolfson/917718d991e7e537fa1bc3b6d39cb3f0 to your computer and use it in GitHub Desktop.
Save twolfson/917718d991e7e537fa1bc3b6d39cb3f0 to your computer and use it in GitHub Desktop.
Proof of concept to demonstrate how `runtime.onMessage` is missing tab in Firefox's responive design mode

gist-web-extension-onMessage

Proof of concept to demonstrate how runtime.onMessage is missing tab in Firefox's responive design mode

Related to: twolfson/livereload-extensions#5

Getting started

Run the following steps to get this proof of concept running:

  • Clone the repository
    git clone <repo_url> gist-web-extension-onMessage
    cd gist-web-extension-onMessage
  • Open Firefox and navigate to about:debugging
  • Add our extension as a temporary add-on
  • Open its "Debug" console
  • Navigate to a normal website (e.g. https://mozilla.org/)
  • Refresh our page and look at our "Debug" console
  • Click our icon, look at "Debug" console, and verify tab ids correspond
  • Enter Responsive Design Mode
  • Refresh our page (in Responsive Design Mode) and look at our "Debug" console
  • Click our icon, look at "Debug" console, and verify tab ids don't correspond/show
  • We'd expect sender.tab to exist in runtime.onMessage but it doesn't
browser.browserAction.onClicked.addListener(function handleAddListener(tab) {
console.log('tab', tab);
console.log('tab.id', tab.id);
});
browser.runtime.onMessage.addListener(function handleMessageListener(message, sender, sendResponse) {
console.log('sender', sender);
console.log('sender.tab', sender.tab);
console.log('sender.tab.id', sender.tab.id);
});
browser.runtime.sendMessage('Hello World!');
{
"manifest_version": 2,
"name": "gist-web-extension-onMessage",
"version": "1.0.0",
"background": {
"scripts": [
"global.js"
]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["injected.js"]
}
],
"web_accessible_resources": [],
"permissions": [
"tabs",
"<all_urls>"
],
"browser_action": {
"default_title": "Enable extension",
"default_icon": "IconDisabled.png"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment