summaryrefslogtreecommitdiff
path: root/ext/js/comm/frame-ancestry-handler.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/comm/frame-ancestry-handler.js')
-rw-r--r--ext/js/comm/frame-ancestry-handler.js26
1 files changed, 8 insertions, 18 deletions
diff --git a/ext/js/comm/frame-ancestry-handler.js b/ext/js/comm/frame-ancestry-handler.js
index 3e58d57b..92ed3b8c 100644
--- a/ext/js/comm/frame-ancestry-handler.js
+++ b/ext/js/comm/frame-ancestry-handler.js
@@ -28,13 +28,10 @@ export class FrameAncestryHandler {
/**
* Creates a new instance.
* @param {import('../comm/cross-frame-api.js').CrossFrameAPI} crossFrameApi
- * @param {number} frameId The frame ID of the current frame the instance is instantiated in.
*/
- constructor(crossFrameApi, frameId) {
+ constructor(crossFrameApi) {
/** @type {import('../comm/cross-frame-api.js').CrossFrameAPI} */
this._crossFrameApi = crossFrameApi;
- /** @type {number} */
- this._frameId = frameId;
/** @type {boolean} */
this._isPrepared = false;
/** @type {string} */
@@ -48,14 +45,6 @@ export class FrameAncestryHandler {
}
/**
- * Gets the frame ID that the instance is instantiated in.
- * @type {number}
- */
- get frameId() {
- return this._frameId;
- }
-
- /**
* Initializes event event listening.
*/
prepare() {
@@ -116,8 +105,9 @@ export class FrameAncestryHandler {
*/
_getFrameAncestryInfo(timeout = 5000) {
return new Promise((resolve, reject) => {
+ const {frameId} = this._crossFrameApi;
const targetWindow = window.parent;
- if (window === targetWindow) {
+ if (frameId === null || window === targetWindow) {
resolve([]);
return;
}
@@ -141,11 +131,10 @@ export class FrameAncestryHandler {
if (params.nonce !== nonce) { return null; }
// Add result
- const {frameId, more} = params;
- results.push(frameId);
+ results.push(params.frameId);
nonce = generateId(16);
- if (!more) {
+ if (!params.more) {
// Cleanup
cleanup();
@@ -167,7 +156,6 @@ export class FrameAncestryHandler {
// Start
this._addResponseHandler(uniqueId, onMessage);
resetTimeout();
- const frameId = this._frameId;
this._requestFrameInfo(targetWindow, frameId, frameId, uniqueId, nonce);
});
}
@@ -208,7 +196,9 @@ export class FrameAncestryHandler {
return;
}
- const frameId = this._frameId;
+ const {frameId} = this._crossFrameApi;
+ if (frameId === null) { return; }
+
const {parent} = window;
const more = (window !== parent);