/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
class DocumentEventWatcher {
#abortController = new AbortController(); /** *StartwatchingforalldocumenteventrelatedtoagivenTargetActor. * *@paramTargetActortargetActor *Thetargetactorfromwhichweshouldobservedocumentevent *@paramObjectoptions *Dictionaryobjectwithfollowingattributes: *-onAvailable:mandatoryfunction *Thiswillbecalledforeachresource.
*/
async watch(targetActor, { onAvailable }) { if (isWorker) { return;
} // Bug 1975277: ignore iframes which are destroying. // The inner-window-destroyed event isn't yet fired and the actor is still // registered, but it no longer has a valid window reference. if (!targetActor.window) { return;
}
// Test-only codepath used to test the AppErrorBoundary displayed when the // toolbox fails to initialize. if (
flags.testing &&
Services.prefs.getBoolPref("devtools.testing.force-server-error", false)
) { thrownew TypeError("Test only server error");
}
const onDocumentEvent = (
name,
{
time, // This will be `true` when the user selected a document in the frame picker tool, // in the toolbox toolbar.
isFrameSwitching, // This is only passed for dom-complete event
hasNativeConsoleAPI, // This is only passed for will-navigate event
newURI, // Are we loading an error page like about:neterror
isErrorPage,
} = {}
) => { // Ignore will-navigate as that's managed by parent-process-document-event.js. // Except frame switching, when selecting an iframe document via the dropdown menu, // this is handled by the target actor in the content process and the parent process // doesn't know about it. if (name == "will-navigate" && !isFrameSwitching) { return;
}
onAvailable([
{
name,
time,
isFrameSwitching, // only send `title` on dom interactive (once the HTML was parsed) so we don't // make the payload bigger for events where we either don't have a title yet, // or where we already had a chance to get the title.
title: name === "dom-interactive" ? targetActor.title : undefined, // only send `url` on dom loading and dom-interactive so we don't make the // payload bigger for other events
url:
name === "dom-loading" || name === "dom-interactive"
? targetActor.url
: undefined, // only send `newURI` on will navigate so we don't make the payload bigger for // other events
newURI: name === "will-navigate" ? newURI : null, // only send `hasNativeConsoleAPI` on dom complete so we don't make the payload bigger for // other events
hasNativeConsoleAPI:
name == "dom-complete" ? hasNativeConsoleAPI : null, // Fallback to undefined to drop the attribute when serializating to JSON
isErrorPage: isErrorPage || undefined,
},
]);
};
this.listener = new DocumentEventsListener(targetActor);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.