diff --git a/toolkit/actors/UserCharacteristicsCanvasRenderingChild.sys.mjs b/toolkit/actors/UserCharacteristicsCanvasRenderingChild.sys.mjs index a76f5b07f06e..dbb86d8dc5c1 100644 --- a/toolkit/actors/UserCharacteristicsCanvasRenderingChild.sys.mjs +++ b/toolkit/actors/UserCharacteristicsCanvasRenderingChild.sys.mjs @@ -52,7 +52,10 @@ export class UserCharacteristicsCanvasRenderingChild extends JSWindowActorChild "Error getting canvas debug info during render: ", await stringifyError(e) ); - return { error: "COULD_NOT_GET_DEBUG_INFO", originalError: e }; + return { + error: "COULD_NOT_GET_DEBUG_INFO", + originalError: await stringifyError(e), + }; } if (debugInfo.isAccelerated !== isAccelerated) { @@ -66,10 +69,13 @@ export class UserCharacteristicsCanvasRenderingChild extends JSWindowActorChild await recipe.func(this.contentWindow, canvas, ctx); } catch (e) { lazy.console.error("Error rendering canvas: ", await stringifyError(e)); - return { error: "RENDERING_ERROR", originalError: e }; + return { + error: "RENDERING_ERROR", + originalError: await stringifyError(e), + }; } - return sha1(canvas.toDataURL("image/png", 1)); + return sha1(canvas.toDataURL("image/png", 1)).catch(stringifyError); }; const data = { diff --git a/toolkit/actors/UserCharacteristicsWindowInfoChild.sys.mjs b/toolkit/actors/UserCharacteristicsWindowInfoChild.sys.mjs index b32658c150da..aea0e837f92e 100644 --- a/toolkit/actors/UserCharacteristicsWindowInfoChild.sys.mjs +++ b/toolkit/actors/UserCharacteristicsWindowInfoChild.sys.mjs @@ -133,7 +133,7 @@ export class UserCharacteristicsWindowInfoChild extends JSWindowActorChild { didDestroy() { this.destroyed = true; for (const [type, handler] of Object.entries(this.handlers)) { - this.contentWindow.windowRoot.removeEventListener(type, handler); + this.contentWindow?.windowRoot?.removeEventListener(type, handler); } } diff --git a/toolkit/components/resistfingerprinting/UserCharacteristicsPageService.sys.mjs b/toolkit/components/resistfingerprinting/UserCharacteristicsPageService.sys.mjs index 5e95b66a195f..b11428ffe74f 100644 --- a/toolkit/components/resistfingerprinting/UserCharacteristicsPageService.sys.mjs +++ b/toolkit/components/resistfingerprinting/UserCharacteristicsPageService.sys.mjs @@ -123,7 +123,9 @@ export class UserCharacteristicsPageService { } finally { lazy.console.debug("Unregistering actors"); this.cleanUp(); + lazy.console.debug("Cleanup done"); this._backgroundBrowsers.delete(browser); + lazy.console.debug("Background browser removed"); } }); } @@ -131,6 +133,7 @@ export class UserCharacteristicsPageService { cleanUp() { ChromeUtils.unregisterWindowActor("UserCharacteristics"); // unregisterWindowActor doesn't throw if the actor is not registered. + // (Do note it console.error's but doesn't throw) // We can safely double unregister. We do this to handle the case where // the actor was registered but the function it was registered timed out. ChromeUtils.unregisterWindowActor("UserCharacteristicsWindowInfo"); @@ -244,10 +247,14 @@ export class UserCharacteristicsPageService { for (const win of Services.wm.getEnumerator("navigator:browser")) { if (!win.closed) { for (const tab of win.gBrowser.tabs) { - const actor = + const actor = await promiseTry(() => tab.linkedBrowser.browsingContext?.currentWindowGlobal.getActor( "UserCharacteristicsWindowInfo" - ); + ) + ).catch(async e => { + lazy.console.error("Error getting actor", e); + this.handledErrors.push(await stringifyError(e)); + }); if (!actor) { continue; @@ -897,3 +904,13 @@ function timeoutPromise(promise, ms) { ); }); } + +function promiseTry(func) { + return new Promise((resolve, reject) => { + try { + resolve(func()); + } catch (error) { + reject(error); + } + }); +} diff --git a/toolkit/components/resistfingerprinting/content/usercharacteristics.js b/toolkit/components/resistfingerprinting/content/usercharacteristics.js index 3a4917511441..0bdd89ece24f 100644 --- a/toolkit/components/resistfingerprinting/content/usercharacteristics.js +++ b/toolkit/components/resistfingerprinting/content/usercharacteristics.js @@ -1062,7 +1062,7 @@ async function startPopulating() { for (const key in data) { try { output[key] = await data[key]; - debug(key, output[key].length); + debug(key, output[key] ? output[key].length : "null"); } catch (e) { debug("Promise rejected for", key, "Error:", e); errors.push(`${key}: ${await stringifyError(e)}`);