Yes, it is possible to ascertain whether a particular subframe (such as an iframe with a source of about:blank) has the same origin as the top frame of the page using Chrome DevTools. The origin of a frame is determined by the scheme (e.g., http/https), host, and port, as per the same-origin policy. For about:blank iframes, the origin typically inherits from the parent document if created in the same context, but this can vary based on how the iframe is loaded (e.g., via JavaScript or HTML).
Chrome DevTools provides several ways to inspect and compare origins. The most straightforward method is using the Application panel, as it explicitly lists the origin for each frame. Below, I'll outline the steps to do this, along with additional methods for verification.
Step-by-Step Guide to Check Frame Origins in Chrome DevTools
-
Open Chrome DevTools:
- Right-click on the web page and select "Inspect" (or press
Ctrl+Shift+I on Windows/Linux or Cmd+Option+I on macOS).
- This opens the DevTools panel.
-
Navigate to the Application Panel:
- In the DevTools toolbar, click on the "Application" tab (it looks like a file folder icon). If you don't see it, you can use the panel switcher at the top to find it.
-
Locate the Frames Section:
- In the Application panel, expand the "Storage" section (on the left sidebar).
- Look for "Frames" or "Frame Hierarchy". This section lists all the frames (including iframes) in a hierarchical tree view.
- Each frame entry will show:
- The frame's URL (e.g.,
about:blank for blank iframes).
- The origin (e.g.,
http://example.com or similar).
- Other details like the frame's ID or name.
-
Identify the Subframe and Compare Origins:
- Find the specific iframe you're interested in (e.g., by its URL or by expanding the tree to locate subframes).
- Note the origin displayed for that subframe.
- Compare it to the origin of the top frame (usually listed at the root of the hierarchy or explicitly labeled as the "top-level frame").
- If the origins match (e.g., both show
http://example.com), then the subframe has the same origin as the top frame.
- For
about:blank iframes:
- If the origin is the same as the parent, it will typically be inherited and shown as such.
- If the iframe was created in a way that isolates it (e.g., via sandbox attributes or cross-origin creation), the origin might be listed as
null or a unique opaque origin, indicating it's not the same.
-
Additional Verification in Other Panels:
- Elements Panel:
- Switch to the "Elements" tab in DevTools.
- Locate the iframe element in the DOM tree (it might have an attribute like
src="about:blank").
- Right-click the iframe element and select "Break on" or use the context menu to inspect it.
- You can also hover over the iframe or use the "Computed" styles to see some attributes, but this doesn't directly show the origin. Instead, use the Console (next step) for more details.
- Console Panel:
- Switch to the "Console" tab.
- Use the context selector dropdown (top-left corner of the Console) to change the execution context to the specific frame (e.g., select the iframe from the list).
- Once in the correct context, run
window.location.origin in the Console. This will return the origin of that frame (e.g., "http://example.com").
- Switch back to the top frame context and run the same command to compare.
- Note: If the frames are cross-origin, you might not be able to access the subframe's context due to the same-origin policy restrictions.
- Network Panel:
- If the iframe loads resources, you can check the Network tab for requests originating from the iframe. The initiator column might show the frame's URL, which can help infer the origin. However, this is less direct for
about:blank iframes since they might not make additional requests.
Key Considerations for about:blank Iframes
- Origin Inheritance: By default, an iframe with
src="about:blank" inherits the origin of the document that created it (e.g., the parent frame). This is because about:blank is a special URL that doesn't specify a new origin. However, if the iframe is created dynamically via JavaScript in a cross-origin context or has attributes like sandbox that restrict it, it might not share the same origin.
- Security Implications: If the origins match, the subframe can interact with the top frame (e.g., access variables or DOM elements). If they don't, you'll see cross-origin restrictions.
- Edge Cases: In rare cases,
about:blank might be loaded in a unique opaque origin (e.g., if created via document.write or other mechanisms). DevTools should reflect this accurately in the Application panel.
Example Scenario
Suppose you're on a page at https://example.com, and there's an iframe with src="about:blank".
- In the Application panel's Frames section, you might see:
- Top frame: URL =
https://example.com, Origin = https://example.com
- Subframe (iframe): URL =
about:blank, Origin = https://example.com (indicating same origin)
- If the origins match, you can confirm the subframe is same-origin.
If you encounter any issues or the information isn't clear, you can also use Chrome's built-in help (search for "Frames" in DevTools documentation) or extensions like the "Chrome DevTools Protocol" for more advanced debugging.
This approach should work in most versions of Chrome, but if you're using an older version, ensure DevTools is up to date by updating your browser. If you have a specific example or more details about the page, I can provide more tailored advice!