From 716e6a68c2be7c5bd1ec9eb068b0e269f8e2bd04 Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Wed, 15 Jun 2022 17:10:16 +0000 Subject: [PATCH] Bug 1761975 - [devtools] Hide ExtensionContent.jsm when debugging page with WebExt content scripts. r=bomsy Differential Revision: https://phabricator.services.mozilla.com/D148837 --- .../browser_dbg-features-source-tree.js | 10 ++----- devtools/server/actors/thread.js | 29 +++++++++++++++++++ devtools/server/tests/xpcshell/testactors.js | 5 ++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-features-source-tree.js b/devtools/client/debugger/test/mochitest/browser_dbg-features-source-tree.js index daad87b2669e..164c092d3ad3 100644 --- a/devtools/client/debugger/test/mochitest/browser_dbg-features-source-tree.js +++ b/devtools/client/debugger/test/mochitest/browser_dbg-features-source-tree.js @@ -393,19 +393,14 @@ add_task(async function testSourceTreeWithWebExtensionContentScript() { let dbg = await initDebugger("doc-content-script-sources.html"); // Let some time for unexpected source to appear await wait(1000); - // Bug 1761975 - While the content script doesn't show up, - // the internals of WebExtension codebase appear in the debugger... - await waitForSourcesInSourceTree(dbg, ["ExtensionContent.jsm"]); + await waitForSourcesInSourceTree(dbg, []); await dbg.toolbox.closeToolbox(); info("With the chrome preference, the content script shows up"); await pushPref("devtools.chrome.enabled", true); const toolbox = await openToolboxForTab(gBrowser.selectedTab, "jsdebugger"); dbg = createDebuggerContext(toolbox); - await waitForSourcesInSourceTree(dbg, [ - "content_script.js", - "ExtensionContent.jsm", - ]); + await waitForSourcesInSourceTree(dbg, ["content_script.js"]); await selectSource(dbg, "content_script.js"); ok( findElementWithSelector(dbg, ".sources-list .focused"), @@ -445,7 +440,6 @@ add_task(async function testSourceTreeNamesForWebExtensions() { "Test content script extension", "Test content script extension is labeled properly" ); - is(getLabel(dbg, 3), "resource://gre", "resource://gre is labeled properly"); await dbg.toolbox.closeToolbox(); await extension.unload(); diff --git a/devtools/server/actors/thread.js b/devtools/server/actors/thread.js index ffd1108ca2c3..a7f5be93a3c5 100644 --- a/devtools/server/actors/thread.js +++ b/devtools/server/actors/thread.js @@ -2056,6 +2056,31 @@ const ThreadActor = ActorClassWithSpec(threadSpec, { this._shouldEmitNewSource = false; }, + /** + * Filtering function to filter out sources for which we don't want to notify/create + * source actors + * + * @param {Debugger.Source} source + * The source to accept or ignore + * @param Boolean + * True, if we want to create a source actor. + */ + _acceptSource(source) { + // We have some spurious source created by ExtensionContent.jsm when debugging tabs. + // These sources are internal stuff injected by WebExt codebase to implement content + // scripts. We can't easily ignore them from Debugger API, so ignore them + // when debugging a tab (i.e. browser-element). As we still want to debug them + // from the browser toolbox. + if ( + this._parent.sessionContext.type == "browser-element" && + source.url.endsWith("ExtensionContent.jsm") + ) { + return false; + } + + return true; + }, + /** * Add the provided source to the server cache. * @@ -2063,6 +2088,10 @@ const ThreadActor = ActorClassWithSpec(threadSpec, { * The source that will be stored. */ _addSource(source) { + if (!this._acceptSource(source)) { + return; + } + // Preloaded WebExtension content scripts may be cached internally by // ExtensionContent.jsm and ThreadActor would ignore them on a page reload // because it finds them in the _debuggerSourcesSeen WeakSet, diff --git a/devtools/server/tests/xpcshell/testactors.js b/devtools/server/tests/xpcshell/testactors.js index 2d9f4abdd25c..c8a3b54b7e8d 100644 --- a/devtools/server/tests/xpcshell/testactors.js +++ b/devtools/server/tests/xpcshell/testactors.js @@ -23,6 +23,9 @@ const { } = require("devtools/shared/specs/targets/window-global"); const { tabDescriptorSpec } = require("devtools/shared/specs/descriptors/tab"); const Targets = require("devtools/server/actors/targets/index"); +const { + createContentProcessSessionContext, +} = require("devtools/server/actors/watcher/session-context"); var gTestGlobals = new Set(); DevToolsServer.addTestGlobal = function(global) { @@ -150,6 +153,8 @@ const TestTargetActor = protocol.ActorClassWithSpec(windowGlobalTargetSpec, { initialize: function(conn, global) { protocol.Actor.prototype.initialize.call(this, conn); this.conn = conn; + + this.sessionContext = createContentProcessSessionContext(); this._global = global; this._global.wrappedJSObject = global; this.threadActor = new ThreadActor(this, this._global);