Bug 1944104 - [devtools] Flag Content Script and WindowGlobal targets with related addon-id. r=devtools-reviewers,bomsy

Differential Revision: https://phabricator.services.mozilla.com/D235679
This commit is contained in:
Alexandre Poirot
2025-02-11 13:41:36 +00:00
parent ba5d494ec5
commit 83d08122aa
5 changed files with 11 additions and 0 deletions

View File

@@ -46,6 +46,7 @@ class WindowGlobalTargetFront extends TargetMixin(
this.innerWindowId = json.innerWindowId;
this.processID = json.processID;
this.isFallbackExtensionDocument = json.isFallbackExtensionDocument;
this.addonId = json.addonId;
// Save the full form for Target class usage.
// Do not use `form` name to avoid colliding with protocol.js's `form` method

View File

@@ -106,6 +106,7 @@ class WebExtensionContentScriptTargetActor extends BaseTargetActor {
return {
actor: this.actorID,
addonId: this.addonId,
// Use the related extension as content script title
// as content scripts have no name, they are just a group of JS files

View File

@@ -41,6 +41,8 @@ ChromeUtils.defineESModuleGetters(
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
WEBEXTENSION_FALLBACK_DOC_URL:
"resource://devtools/server/actors/watcher/browsing-context-helpers.sys.mjs",
getAddonIdForWindowGlobal:
"resource://devtools/server/actors/watcher/browsing-context-helpers.sys.mjs",
},
{ global: "contextual" }
);
@@ -691,6 +693,7 @@ class WindowGlobalTargetActor extends BaseTargetActor {
// Specific to Web Extension documents
isFallbackExtensionDocument: this.#isFallbackExtensionDocument,
addonId: lazy.getAddonIdForWindowGlobal(this.window.windowGlobalChild),
traits: {
// @backward-compat { version 64 } Exposes a new trait to help identify

View File

@@ -101,6 +101,11 @@ add_task(async function () {
}
);
const targets = await targetCommand.getAllTargets(targetCommand.ALL_TYPES);
for(const targetFront of targets) {
is(targetFront.addonId, extension.id, `Target ${targetFront.actorID} has the right addonId attribute`);
}
await targetCommand.reloadTopLevelTarget();
info("Wait for next dom-loading DOCUMENT_EVENT");

View File

@@ -213,6 +213,7 @@ async function testWebExtension() {
"the web extension target is of frame type, because it inherits from WindowGlobalTargetActor"
);
is(targetFront.isTopLevel, true, "This is flagged as top level");
is(targetFront.addonId, extension.id, "The addonId attribute is correct");
targetCommand.destroy();