Returns the frame ID of any window global or frame element when called from a content script or extension page, including background pages.
On this page
runtime.getFrameId()
Syntax
let gettingInfo = browser.runtime.getFrameId(
target // object
)
Parameters
-
target
-
A WindowProxy or a browsing context container Element (iframe, frame, embed, or object) for the target frame.
Return value
Returns the frame ID of the target frame, or -1 if the frame doesn't exist.
Examples
This code recursively walks descendant frames and gets parent frame IDs.
const parents = {};
function visit(win) {
const frameId = browser.runtime.getFrameId(win);
const parentId = browser.runtime.getFrameId(win.parent);
parents[frameId] = win.parent !== win ? parentId : -1;
try {
const frameEl = browser.runtime.getFrameId(win.frameElement);
browser.test.assertEq(frameId, frameEl, "frameElement id correct");
} catch (e) {
// Can't access a cross-origin .frameElement.
}
for (const frame of win.frames) {
visit(frame);
}
}
visit(window);
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
getFrameId |
No | No | 96 | ? | No | 16 | ? | ? | 96 | ? | 16 | ? |
Note: Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/getFrameId