Bug 296702
| Summary: | browser.scripting.executeScript() does not inject scripts into about:blank and about:srcdoc frames | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Andrey Meshkov <am> |
| Component: | WebKit Extensions | Assignee: | Nobody <webkit-unassigned> |
| Status: | NEW | ||
| Severity: | Normal | CC: | am, timothy, webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Safari 18 | ||
| Hardware: | All | ||
| OS: | All | ||
Andrey Meshkov
## Description
browser.scripting.executeScript does not inject scripts into about:blank and about:srcdoc frames.
It returns "Failed to execute script. Extension does not have access to this frame." even though content script is allowed to run in these frames.
## Steps to reproduce
Create a test extension to reproduce this issue.
Manifest:
```
{
...
"background": {
"scripts": [
"background.js"
],
"type": "module"
},
"content_scripts": [
{
"js": [
"content.js"
],
"matches": [
"<all_urls>"
],
"run_at": "document_start",
"all_frames": true,
"match_about_blank": true,
"match_origin_as_fallback": true
}
],
...
"permissions": [
"<all_urls>",
...,
"scripting"
]
}
```
Content script:
```
browser.runtime.sendMessage({});
```
Background page:
```
browser.runtime.onMessage.addListener(async (request, sender) => {
const tabId = sender.tab?.id ?? 0;
const frameId = sender.frameId ?? 0;
const result = await browser.scripting.executeScript({
target: {
tabId: tabId,
frameIds: [frameId]
},
func: (id) => { console.log(`injected into ${id}!`) },
args: [frameId],
world: 'MAIN',
injectImmediately: true,
});
console.log(result);
})
```
Install it and open the test page:
https://testcases.agrd.dev/Filters/extended-css-rules/extended-css-iframejs-injection/extended-css-iframejs-injection
Open Dev tools and look for "injected into ${id}" messages in the console.
## Expected result
Four messages (one for the main frame, three for iframes).
## Actual result
Two messages (one for the main frame, one for an iframe with URL).
If you inspect the background page, you'll see that they failed due to "Failed to execute script. Extension does not have access to this frame.".
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/157118726>