You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 14, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 14, 2024. It is now read-only.
⚠️ This is for issues with the https://developer.chrome.com site, not Chromium itself.
If you want to file a bug with Chromium (the open-source project behind Google Chrome and other browsers), please use https://crbug.com.
Describe the bug
The documentation for the ScriptInjection doesn't seem to be correct.
If I provide a func I get the error:
Uncaught TypeError: Error in invocation of scripting.executeScript(scripting.ScriptInjection injection, optional function callback): Error at parameter 'injection': Unexpected property: 'func'.
at <anonymous>:1:26
I figured out that the actual key needed is function, not func, but I have the same problem with args:
VM172:1 Uncaught TypeError: Error in invocation of scripting.executeScript(scripting.ScriptInjection injection, optional function callback): Error at parameter 'injection': Unexpected property: 'args'.
at <anonymous>:1:26
To Reproduce
Steps to reproduce the behavior:
Setup a basic Chrome extension using Manifest 3 and the scripting permission
Either in the extension console, or in a source file run the below code:
Using a correct tabId, and you should see the error.
Expected behavior
Error should not happen, and if I understand the documentation correctly, the function should return a promise that resolves with a value of 5. Perhaps the documentation is wrong and not referencing the correct key name, and knowing that might make this work.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Looks like the func change was made for version 92.0.4484.0 and the args change is part of 92.0.4514.0
It looks like the latest stable version is 91.0.4472.77. I just installed the unstable version of chrome to test it out which is at 92.0.4515.40 (ahead of the func and args changes and it seems to be working).
So I guess the documentation is ahead of the stable chrome release right now.
@hallzy, you've hit the nail on the head. Our docs reflect the tip of the main branch in Chromium.
For a bit more context, the first implementation of function support in this API used the property name function for the function you pass in. This had a major drawback, though, in that this effectively prohibited developers from using object shorthand; since "function" is a reserved keyword in JS, devs can't create variable named "function", but they can assign properties with that name.
In order to accommodate developers using object shorthand, we decided to renamed function to func and arguments to args. Unfortunately this broke a few users and caused a short term disconnect between Chrome Stable and Beta/Canary, but in the long term this should make it easier to write extensions with idiomatic JS patterns.
Thanks. Yeah, I noticed there was an explanation in the Chromium code about that so that all makes sense. Was just very confused that the documented keys didn't work.
I'll close this. Might be useful to have chrome version numbers on stuff like that in the documentation to avoid confusion, but maybe changes like this aren't all that common anyways.
I'll just test my extension using unstable for now and add a minimum chrome version to the manifest and leave it at that
Activity
robdodson commentedon Jun 2, 2021
@dotproto do the docs seem incorrect here?
hallzy commentedon Jun 2, 2021
I found these changes in the chromium repo
Replacement of
functionwithfunc: chromium/chromium@1f6eb20Addition of
args: chromium/chromium@71ee034Looks like the
funcchange was made for version 92.0.4484.0 and theargschange is part of 92.0.4514.0It looks like the latest stable version is 91.0.4472.77. I just installed the unstable version of chrome to test it out which is at 92.0.4515.40 (ahead of the
funcandargschanges and it seems to be working).So I guess the documentation is ahead of the stable chrome release right now.
dotproto commentedon Jun 3, 2021
@hallzy, you've hit the nail on the head. Our docs reflect the tip of the main branch in Chromium.
For a bit more context, the first implementation of function support in this API used the property name
functionfor the function you pass in. This had a major drawback, though, in that this effectively prohibited developers from using object shorthand; since "function" is a reserved keyword in JS, devs can't create variable named "function", but they can assign properties with that name.In order to accommodate developers using object shorthand, we decided to renamed
functiontofuncandargumentstoargs. Unfortunately this broke a few users and caused a short term disconnect between Chrome Stable and Beta/Canary, but in the long term this should make it easier to write extensions with idiomatic JS patterns.hallzy commentedon Jun 3, 2021
Thanks. Yeah, I noticed there was an explanation in the Chromium code about that so that all makes sense. Was just very confused that the documented keys didn't work.
I'll close this. Might be useful to have chrome version numbers on stuff like that in the documentation to avoid confusion, but maybe changes like this aren't all that common anyways.
I'll just test my extension using unstable for now and add a minimum chrome version to the manifest and leave it at that
Thanks