Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browser(firefox): do not double-attach session to the same target #4027

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions browser_patches/firefox/BUILD_NUMBER
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1177
Changed: [email protected] Wed Sep 30 03:11:29 MDT 2020
1178
Changed: [email protected] Wed Sep 30 23:36:27 PDT 2020
11 changes: 7 additions & 4 deletions browser_patches/firefox/juggler/TargetRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ class TargetRegistry {

const sessions = [];
const readyData = { sessions, target };
this.emit(TargetRegistry.Events.TargetCreated, readyData);
target.markAsReported();
this.emit(TargetRegistry.Events.TargetCreated, readyData);
return {
scriptsToEvaluateOnNewDocument: target.browserContext().scriptsToEvaluateOnNewDocument,
bindings: target.browserContext().bindings,
Expand Down Expand Up @@ -321,8 +321,8 @@ class TargetRegistry {
return target.id();
}

targets() {
return Array.from(this._browserToTarget.values());
reportedTargets() {
return Array.from(this._browserToTarget.values()).filter(pageTarget => pageTarget._isReported);
}

targetForBrowser(browser) {
Expand Down Expand Up @@ -364,6 +364,7 @@ class PageTarget {
helper.addProgressListener(tab.linkedBrowser, navigationListener, Ci.nsIWebProgress.NOTIFY_LOCATION),
];

this._isReported = false;
this._reportedPromise = new Promise(resolve => {
this._reportedCallback = resolve;
});
Expand All @@ -379,6 +380,7 @@ class PageTarget {
}

markAsReported() {
this._isReported = true;
this._reportedCallback();
}

Expand Down Expand Up @@ -491,7 +493,8 @@ class PageTarget {
this._registry._browserToTarget.delete(this._linkedBrowser);
this._registry._browserBrowsingContextToTarget.delete(this._linkedBrowser.browsingContext);
helper.removeListeners(this._eventListeners);
this._registry.emit(TargetRegistry.Events.TargetDestroyed, this);
if (this._isReported)
this._registry.emit(TargetRegistry.Events.TargetDestroyed, this);
}
}

Expand Down
9 changes: 5 additions & 4 deletions browser_patches/firefox/juggler/content/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ const applySetting = {
};

function initialize() {
const loadContext = docShell.QueryInterface(Ci.nsILoadContext);
const userContextId = loadContext.originAttributes.userContextId;

const response = sendSyncMessage('juggler:content-ready', { userContextId })[0];
const response = sendSyncMessage('juggler:content-ready')[0];
// If we didn't get a response, then we don't want to do anything
// as a part of this frame script.
if (!response)
return;
const {
sessionIds = [],
scriptsToEvaluateOnNewDocument = [],
Expand Down
2 changes: 1 addition & 1 deletion browser_patches/firefox/juggler/protocol/BrowserHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BrowserHandler {
this._enabled = true;
this._attachToDefaultContext = attachToDefaultContext;

for (const target of this._targetRegistry.targets()) {
for (const target of this._targetRegistry.reportedTargets()) {
if (!this._shouldAttachToTarget(target))
continue;
const session = this._dispatcher.createSession();
Expand Down