all_frames not recognized/ "unexpected property"?

207 views
Skip to first unread message

densch123

unread,
Oct 1, 2022, 4:23:11 PM10/1/22
to Chromium Extensions
Hi, I am building s chrome extension that should inject a .js into every frame.
for that I have this manifest.json:
{
  "name": "Test3",
  "description": "blabla",
  "version": "1.0",
  "manifest_version": 3,
     "background": {"service_worker": "bg.js"},
  "permissions": ["scripting","webRequest"],
  "host_permissions": ["<all_urls>"]
}

bg.js looks like this:

chrome.runtime.onInstalled.addListener(async () => {
  const old = await chrome.scripting.getRegisteredContentScripts();
  if (old[0]) await chrome.scripting.unregisterContentScripts({ids: old.map(s => s.id)});
  await chrome.scripting.registerContentScripts([{
    id: 'write',
    js: ['write.js'],
    matches: ['<all_urls>'],
    all_frames: true,
    runAt: 'document_end',
    world: 'MAIN',
  }]);
});

posting write.js here would be pointless a it is logn code and basically jsut is a fucntion (and it's execution) that for each XMLHTTPRequest, read's out it's data like response body and such and draws colored boxes based on it. all that code in the write.js shouldnt matter here).

anyways manifest.json and bg.js are as above.

Before I didnt have the all_frames:true, line in it and it worked in the sense that it injected the content script once at the very beginning. but since the used site changes depedning on user interaction (roulette site), the injected content script jsut stops working.
googling stuff, it was recommended to insert all_frames:true since that would inject the content script into all iframes and that jmight solve stuff.


however loading/installing the whole thing, it directly shows me the error

Uncaught (in promise) TypeError: Error in invocation of scripting.registerContentScripts(array scripts, optional function callback): Error at parameter 'scripts': Error at index 0: Unexpected property: 'all_frames'.

so he somehow has a big issue with all_frame being placed there but I dont get why.
the official contentscript documentation of chrome literally shows examples looking exactly as I have it. but it jsut doesnt work :-/

Anyone can offer help?

densch123

unread,
Oct 1, 2022, 4:34:33 PM10/1/22
to Chromium Extensions, densch123
Guess I already solved this tiny issue by myself, as on another chrome site I found the property allFrames isntead, which instead works.
Chrome really shouldnt write stuff like this
https://developer.chrome.com/docs/extensions/mv3/content_scripts/#frames
on their website if it ain't true :-/


Sadly it didnt solve my initial problem.
The initially injected contentscript still doesnt seem to catch any of the requests.
This worked perfect on a roulette simulator but doesnt work in the actualy online casinos table.
the second the table is visually loaded, the contentscript jsut stops working.
no request caught or processed anymore, even simple console.logs arent executed anymore.

Is it possible that the roulette sites jsut somehow blocks the contentscript from working in general? :-(

It's driving mye crazy that the perfectly working injected contentscript jsut stops working the milisecond the online casinos table is loaded.

and I know nfor a fact that there are all sorts of http requests (inscluding the specific ones I want) since I can wathc them appear live in the network tab of chromes developer console!
yet nonetheless the contentscript either jsut doesnt work anxmore in general or jsut doesnt catch any requests anymore O_o

wOxxOm

unread,
Oct 1, 2022, 6:19:18 PM10/1/22
to Chromium Extensions, schue...@gmail.com
The name registerContentScripts is misleading in this case because your injected script is not a content script anymore: it runs in MAIN world, so it's just a normal page script in the JS environment controlled by the page. Try setting runAt: 'document_start' and optionally rework the code as it'll be running before document.head or body exist. Maybe matchOriginAsFallback: true too in case the site is doing it in an iframe.

As for the documentation, it is entirely correct: chrome API uses camelCase for key names while snake_case is for manifest.json. You can suggest them to note it explicitly, there's a bug link at the end of the page, although changing the letter case is normal in JS and DOM/CSS e.g. data-foo-bar attribute becomes dataset.fooBar and flex-wrap in CSS becomes element.style.flexWrap. Still, it'd be a good thing to mention explicitly at least in this article about content scripts.
Reply all
Reply to author
Forward
0 new messages