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:
<script context="module" lang="ts">
import type {
PlasmoCSConfig,
PlasmoGetInlineAnchor,
PlasmoMountShadowHost
} from "plasmo"

export const config: PlasmoCSConfig = {
matches: ["https://www.youtube.com/*"],
world: "MAIN",
run_at: "document_start"
}

export const getInlineAnchor: PlasmoGetInlineAnchor = () =>
document.querySelector("#primary-inner > #below")

export const mountShadowHost: PlasmoMountShadowHost = ({
anchor, shadowHost
}) => {
anchor!.element!.prepend(shadowHost)
}
</script>

<script lang="ts">
const player: any = document.getElementById("movie_player")
console.log(player);
console.log(player.getDuration());
console.log(player.getCurrentTime());
</script>

<p style="color: white;">helloooooooooooooooo world</p>
<script context="module" lang="ts">
import type {
PlasmoCSConfig,
PlasmoGetInlineAnchor,
PlasmoMountShadowHost
} from "plasmo"

export const config: PlasmoCSConfig = {
matches: ["https://www.youtube.com/*"],
world: "MAIN",
run_at: "document_start"
}

export const getInlineAnchor: PlasmoGetInlineAnchor = () =>
document.querySelector("#primary-inner > #below")

export const mountShadowHost: PlasmoMountShadowHost = ({
anchor, shadowHost
}) => {
anchor!.element!.prepend(shadowHost)
}
</script>

<script lang="ts">
const player: any = document.getElementById("movie_player")
console.log(player);
console.log(player.getDuration());
console.log(player.getCurrentTime());
</script>

<p style="color: white;">helloooooooooooooooo world</p>
38 Replies
evan
evanOPβ€’13mo ago
screenshot of the error:
No description
realxslinger
realxslingerβ€’11mo ago
Has anyone ever found a solution to this issue?
evan
evanOPβ€’11mo ago
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+
YAGPDB.xyz
YAGPDB.xyzβ€’11mo ago
Gave +1 Rep to @avi12
evan
evanOPβ€’11mo ago
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)
Arcane
Arcaneβ€’11mo ago
@evan has reached level 1. GG!
evan
evanOPβ€’11mo ago
(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 😭
Avi
Aviβ€’11mo ago
If you can't update Firefox, either research why you get the error or reinstall Firefox
evan
evanOPβ€’11mo ago
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)?
Avi
Aviβ€’11mo ago
I mean, try to run chrome.sxripting into the background script console
evan
evanOPβ€’11mo ago
it looks like both chrome.scripting and chrome.scripting.registerContentScripts exist, but im not sure what else i should be looking for
Avi
Aviβ€’11mo ago
I'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(...)
evan
evanOPβ€’11mo ago
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 context
Avi
Aviβ€’11mo ago
I made plenty of Chrome extensions for YouTube, check my repo
evan
evanOPβ€’11mo ago
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
Arcane
Arcaneβ€’11mo ago
@evan has reached level 2. GG!
evan
evanOPβ€’11mo ago
i didnt look through it carefully though, please let me know if you have any examples
Avi
Aviβ€’11mo ago
You might not need #movie_player specifically Again, I don't know anything regarding your wxt's logic, what you need to achieve
evan
evanOPβ€’11mo ago
my end goal is to get the current video time, including milliseconds
Avi
Aviβ€’11mo ago
You don't need Plasmo to do it
Avi
Aviβ€’11mo ago
MDN Web Docs
HTMLMediaElement: currentTime property - Web APIs | MDN
The HTMLMediaElement interface's currentTime property specifies the current playback time in seconds.
evan
evanOPβ€’11mo ago
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
Avi
Aviβ€’11mo ago
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 it
evan
evanOPβ€’11mo ago
yeah 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
Avi
Aviβ€’11mo ago
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.
Avi
Aviβ€’11mo ago
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 doable
evan
evanOPβ€’11mo ago
hmmmmmm 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
YAGPDB.xyz
YAGPDB.xyzβ€’11mo ago
Gave +1 Rep to @avi12
evan
evanOPβ€’11mo ago
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 project
Avi
Aviβ€’11mo ago
Listen to whether an element related to advertisment exists
evan
evanOPβ€’11mo ago
ohhh i see, thanks thats super helpful
Avi
Aviβ€’4mo ago
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 […]
Avi
Aviβ€’4mo ago
MDN Web Docs
scripting.RegisteredContentScript - Mozilla | MDN
This object contains details of a script to be registered or that is registered.
evan
evanOPβ€’4mo ago
oh noooooo ......... thx for letting me know πŸ˜”πŸ‘
Avi
Aviβ€’4mo ago
IKR 😬 I'll have to figure out a workaround for YTTM as well πŸ˜…
Want results from more Discord servers?
Add your server