runtime.getFrameId()
Returns the frame ID of any window global or frame element when called from a content script or extension page, including background pages.
Syntax
var gettingInfo = browser.runtime.getFrameId()
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.
let parents = {};
function visit(win) {
let frameId = browser.runtime.getFrameId(win);
let parentId = browser.runtime.getFrameId(win.parent);
parents[frameId] = (win.parent != win) ? parentId : -1;
try {
let frameEl = browser.runtime.getFrameId(win.frameElement);
browser.test.assertEq(frameId, frameEl, "frameElement id correct");
} catch (e) {
// Can't access a cross-origin .frameElement.
}
for (let i = 0; i < win.frames.length; i++) {
visit(win.frames[i]);
}
}
visit(window);
Browser compatibility
No compatibility data found for webextensions.api.runtime.getFrameId
.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.
Note: Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.