CSUI main world on Firefox MV2 (Unexpected property "world" for scripting.registerContentScripts)
i'm trying to inject my content script UI to the main world - it's working as intended with
plasmo dev --target=chrome-mv3
, but it's not working for plasmo dev --target=firefox-mv2
(no CSUI shows up on the page). is injecting to the main world supported for mv2? if not, are there any alternative ways to execute a pre-existing function from the main world and return the data to the CSUI? thanks!
the error in devtools is: Uncaught Error: Type error for parameter scripts (Error processing 0: Unexpected property "world") for scripting.registerContentScripts.
(screenshot attached)
possibly relevant project information:
- the project is bootstrapped with pnpm create plasmo --with-svelte
- the package.json
has manifest.browser_specific_settings
set and the permissions
contains activeTab, scripting, tabs
- the relevant code is:
38 Replies
screenshot of the error:
Has anyone ever found a solution to this issue?
Interesting, try to run Firefox 102+ https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/registerContentScripts
MDN Web Docs
scripting.registerContentScripts() - Mozilla | MDN
Registers one or more content scripts.
thanks for the response! im not sure what firefox version i was using at the time, but i always keep it up to date, so im pretty sure it was version 102+
Gave +1 Rep to @avi12
im currently trying to reproduce the problem on firefox version 121.0 but im running into a different error π
i will ping you once i get something running π
update @avi12: the error has been reproduced on Mozilla Firefox 121.0 :(
below is a screenshot of the error - it seems like its creating an infinite loop now (not sure if its because of the firefox updates or because of the plasmo 0.83 -> 0.84 update)
@evan has reached level 1. GG!
(currently it shows the error
Unexpected property "world"
, then the error Firefox canβt establish a connection to the server at wss://localhost:XXXX/.
, and repeats indefinitely)
FYI im loading the extension as a Temporary Add-on
, here is a screenshot of the page
it also shows the firefox version number at the top
please let me know if you have any idea of what might be going wrong, im really lost with this error πIf you can't update Firefox, either research why you get the error or reinstall Firefox
firefox version 121 should be far past version 102 right, so it should have the scripting method available? i believe its the most recent stable version, but i can try reinstalling if you think itd help
just to confirm, is this snippet of code above ^ working on your end (or expected to work)?
I mean, try to run
chrome.sxripting
into the background script consoleit looks like both
chrome.scripting
and chrome.scripting.registerContentScripts
exist, but im not sure what else i should be looking forI'm not sure what is the desired logic so I can't help too much
If you need to send a message from the content script then use a Port, i.e. chrome.runtimr.conect(...)
so my desired logic is to interact with the youtube
#movie_player
object
im trying to achieve that by mounting a svelte module to the world contextI made plenty of Chrome extensions for YouTube, check my repo
yes i actually scanned through your github a few months ago, but i didnt see any extensions that make use of the
#movie_player
object and its JS functions@evan has reached level 2. GG!
i didnt look through it carefully though, please let me know if you have any examples
You might not need
#movie_player
specifically
Again, I don't know anything regarding your wxt's logic, what you need to achievemy end goal is to get the current video time, including milliseconds
You don't need Plasmo to do it
MDN Web Docs
HTMLMediaElement: currentTime property - Web APIs | MDN
The HTMLMediaElement interface's
currentTime property specifies the current playback time
in seconds.
ah i have a bunch of UI stuff thats difficult to organize without svelte lol, so i figured plasmo would help with organization
oh thats super interesting hmm
Also, don't target
#movie_player
, target a general selector like video
I'm using Plasmo in my projects because it's convenient, not because I can't make ext's without ityeah i have a proof of concept using raw javascript lol, but its like a few hundred lines and styled with in-line css π
i could configure a bundler to help organize things, but i figured using plasmo would be easier at that point
That's why I'm using Plasmo, because it's convenient
The thing is, I'm trying not to rely on Chrome APIs to achieve what I need
I'm trying to achieve everything using DOM, and it's quite capable with APIs like https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
MDN Web Docs
MutationObserver - Web APIs | MDN
The MutationObserver interface provides the ability to watch for changes being made to the DOM tree. It is designed as a replacement for the older Mutation Events feature, which was part of the DOM3 Events specification.
Last week I discovered that if you want to send HTTP requests (Fetch) and you don't need cookies, you can just send the requests without adding the domain to
host_permissions
I dunno if such an ext will get approved in CWS, but such a functionality is doablehmmmmmm i see, i guess i ll have to interact with the youtube video using the DOM instead of directly using JS in the page
thanks for sending this, seems like its able to get and set the video time with low latency
Gave +1 Rep to @avi12
the only noticeable difference is that it doesnt distinguish between advertisements - when an ad is playing, the youtube
getDuration()
functions return the video duration, but the DOM returns the ad duration
but if i can get past that, it should be all i need for this projectListen to whether an element related to advertisment exists
GitHub
youtube-like-dislike-shortcut/src/contents/csui-ytr-auto-like-perce...
Like videos with Shift+Plus, dislike with Shift+Minus. - avi12/youtube-like-dislike-shortcut
ohhh i see, thanks thats super helpful
Soon enough you might need a workaround https://mspoweruser.com/youtube-testing-untrackable-ads-to-bypass-ad-blockers-server-side-ad-injection/
Pradeep Viswav
MSPoweruser
YouTube testing untrackable ads to bypass ad blockers: server-side ...
Google is locked in a battle with ad blockers, especially on YouTube. Ad revenue is crucial for Google, and viewers using ad blockers limit their income. In the past, Google has tried various tactics to curb ad blockers, but with limited success. Now, theyβre testing a new strategy: server-side ad injection. This means ads would [β¦]
BTW, now I need help with using https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/RegisteredContentScript π
MDN Web Docs
scripting.RegisteredContentScript - Mozilla | MDN
This object contains details of a script to be registered or that is registered.
oh noooooo .........
thx for letting me know ππ
IKR π¬
I'll have to figure out a workaround for YTTM as well π