Content JavaScript does not load for my Extension. Pop up HTML debug does not show any error. Debug website page that I run my extension on, just shows console message "undefined: undefined" with no further information.
Categories
(WebExtensions :: Untriaged, defect)
Tracking
(firefox123 affected, firefox124 affected, firefox125 affected)
People
(Reporter: gum1900, Unassigned)
References
Details
Attachments
(3 files)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 CCleaner/121.0.0.0
Steps to reproduce:
I wrote a small extension with "manifest version 3" based on Mozilla example for "manifest version 2". The extension has a pop-up HTML, a CSS and a JS. At the end of pop-up JS, I coded to load and run a content JS. Please note - the extension works very well on CCleaner and Chrome browsesr. I have written the extension to be compatible with both Firefox and Chrome.
Important files:
pup-up: ./popup/choose_beast.html, ./popup/choose_beast.js, ./popup/choose_beast.css
Content JS: ./content-scripts/beastify.js
manifest: ./manifest.json
Other supporting files: ./beasts/, ./icons/
Actual results:
Content JS never seems to run. Any console message in content JS never show up. Debugger of any website I run my extension on (e.g. http://example.com/) does not list or show the source code of content JS.
Only error message I see in console of pop-up or extension debugger is "undefined: undefined". Beyond that message, debugger does not provide any information. debugger does not show where the above error is occurring.
Expected results:
Pop-up JS loads and runs content script and shows up popu-up HTML with beast options.
When user (or I) click one of the beast names listed, Pop-up JS enforce a CSS to hide all current web-page contents and sends message to content JS. Content JS then display the selected Beast.
Please note - the extension works very well on CCleaner and Chrome browser. I have written the extension to be compatible with both Firefox and Chrome.
Updated•2 years ago
|
Comment 1•2 years ago
|
||
Hello,
I reproduced the issue on the latest Release (123.0.1/20240304104836), Beta (124.0b9/20240308091626) and Nightly (125.0a1/20240310211048) under Windows 10 x64 and Ubuntu 22.04 LTS.
While on http://example.com/, when I click the toolbar button of the extension to grant it permissions to run on the page, indeed an undefined: undefined error message is displayed in the web console. Once the extension UI shows up and I click on any of the entries, an error Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist. error is displayed in the extension console/browser console.
The picture with the chosen animal is not displayed nonetheless.
For more details, see the attached screenshots.
Comment 2•2 years ago
|
||
Comment 3•2 years ago
|
||
Comment 4•2 years ago
|
||
This is not a Firefox bug; this should have been filed as an issue at https://github.com/mdn/webextensions-examples
I see a PR at https://github.com/mdn/webextensions-examples/pull/555
Note: the "not working" part is due to the host permissions being opt-in for MV3 extensions.
| Reporter | ||
Comment 5•2 years ago
|
||
(In reply to Rob Wu [:robwu] from comment #4)
This is not a Firefox bug; this should have been filed as an issue at https://github.com/mdn/webextensions-examples
I see a PR at https://github.com/mdn/webextensions-examples/pull/555
Note: the "not working" part is due to the host permissions being opt-in for MV3 extensions.
Hello Rob,
I guess you misunderstood my issue. I myself filed PR at https://github.com/mdn/webextensions-examples/pull/555 is filed . webextesions-examples are MV2. So I tried that particular one as MV3. The MV3 version works well on Chrome, and I filed PR to review.
But that MV3 version fails with hardly any error details, as I explained in this bug.
I am reopening the bug to review again for you. Thanks.
| Reporter | ||
Comment 6•2 years ago
|
||
(In reply to Rob Wu [:robwu] from comment #4)
This is not a Firefox bug; this should have been filed as an issue at https://github.com/mdn/webextensions-examples
I see a PR at https://github.com/mdn/webextensions-examples/pull/555
Note: the "not working" part is due to the host permissions being opt-in for MV3 extensions.
Hello Rob,
I guess you misunderstood my issue. I myself filed PR at https://github.com/mdn/webextensions-examples/pull/555 .
webextesions-examples are MV2. So I tried that particular one as MV3. The MV3 version works well on Chrome, and I filed PR to review.
But that MV3 version on Firefox fails with hardly any error details, as I explained in this bug.
I am reopening the bug to review again for you. Thanks.
Comment 7•2 years ago
|
||
Your claim is that there is a bug in Firefox because the code you shared works in Chrome.
The relevant logic is in popup/choose_beast.js (loaded from popup/choose_beast.html), which has the following call:
return browser.scripting
.executeScript({
files : [ "./content_scripts/beastify.js"],
The file is at content_scripts/beastify.js.
Because the code is executing in popup/choose_beast.html, Firefox resolves the relative ./ URL to popup/, and tries to look up the file from popup/content_scripts/beastify.js.
I'd argue that Firefox's behavior is correct here - the URL is resolved relative to its caller.
If you want to get the same behavior from Chrome in Firefox, use /content_scripts/beastify.js (note: starts with / instead of ./).
I'm closing this bug because Firefox's behavior of scripting.executeScript is as expected.
I'll file a separate bug about improving the undefined: undefined error.
Description
•