<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>296702</bug_id>
          
          <creation_ts>2025-07-30 08:45:13 -0700</creation_ts>
          <short_desc>browser.scripting.executeScript() does not inject scripts into about:blank and about:srcdoc frames</short_desc>
          <delta_ts>2025-07-30 08:46:55 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKit Extensions</component>
          <version>Safari 18</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Andrey Meshkov">am</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>am</cc>
    
    <cc>timothy</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2133408</commentid>
    <comment_count>0</comment_count>
    <who name="Andrey Meshkov">am</who>
    <bug_when>2025-07-30 08:45:13 -0700</bug_when>
    <thetext>## Description

browser.scripting.executeScript does not inject scripts into about:blank and about:srcdoc frames.
It returns &quot;Failed to execute script. Extension does not have access to this frame.&quot; even though content script is allowed to run in these frames.

## Steps to reproduce

Create a test extension to reproduce this issue.

Manifest:

```
{
    ...
    &quot;background&quot;: {
        &quot;scripts&quot;: [
            &quot;background.js&quot;
        ],
        &quot;type&quot;: &quot;module&quot;
    },
    &quot;content_scripts&quot;: [
        {
            &quot;js&quot;: [
                &quot;content.js&quot;
            ],
            &quot;matches&quot;: [
                &quot;&lt;all_urls&gt;&quot;
            ],
            &quot;run_at&quot;: &quot;document_start&quot;,
            &quot;all_frames&quot;: true,
            &quot;match_about_blank&quot;: true,
            &quot;match_origin_as_fallback&quot;: true
        }
    ],
    ...
    &quot;permissions&quot;: [
        &quot;&lt;all_urls&gt;&quot;,
        ...,
        &quot;scripting&quot;
    ]
}
```

Content script:

```
browser.runtime.sendMessage({});
```

Background page:

```
browser.runtime.onMessage.addListener(async (request, sender) =&gt; {
    const tabId = sender.tab?.id ?? 0;
    const frameId = sender.frameId ?? 0;

    const result = await browser.scripting.executeScript({
        target: {
            tabId: tabId,
            frameIds: [frameId]
        },
        func: (id) =&gt; { console.log(`injected into ${id}!`) },
        args: [frameId],
        world: &apos;MAIN&apos;,
        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 &quot;injected into ${id}&quot; 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&apos;ll see that they failed due to &quot;Failed to execute script. Extension does not have access to this frame.&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2133409</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-07-30 08:45:23 -0700</bug_when>
    <thetext>&lt;rdar://problem/157118726&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>