Search code examples
google-chrome-extensionchrome-extension-manifest-v3

chrome.scripting.executeScript `runAt` property in Manifest v3


I haven't found any mentions of the runAt property in the documentation for the new chrome.scripting.executeScript method.

These are potential properties for the ScriptInjection object: https://developer.chrome.com/docs/extensions/reference/scripting/#type-ScriptInjection.

And these are potential properties for the InjectionTarget object, which is inside the ScriptInjection object: https://developer.chrome.com/docs/extensions/reference/scripting/#type-InjectionTarget.

There is no mention of runAt for ScriptInjection type.

But with tabs.executeScript we can specify runAt property.

How can we do this with manifest v3?


Solution

  • You can now injectImmediately : true,.

    await chrome.scripting.executeScript({
        target: {
            tabId : await getCurrentTabId(),
            allFrames : true,
        },
        world: 'MAIN',
        injectImmediately : true,
        func: () => console.log('test')
    });