Bug 1761975 - [devtools] Hide ExtensionContent.jsm when debugging page with WebExt content scripts. r=bomsy

Differential Revision: https://phabricator.services.mozilla.com/D148837
This commit is contained in:
Alexandre Poirot 2022-06-15 17:10:16 +00:00
parent afad4c3c85
commit 716e6a68c2
3 changed files with 36 additions and 8 deletions

View File

@ -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();

View File

@ -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,

View File

@ -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);