Skip to content

Commit c0db8f7

Browse files
committed
Bug 1941006 - [devtools] Fix DevTools when debugging a page with an extension document used in an iframe. r=jdescottes,devtools-reviewers
Bug 1214658 hacks the content script sandboxes to used them for iframes loading extension documents. These documents expect the privileged chrome/browser APIs, which are exposed by spawning a content script sandboxes. These sandboxes won't have any metadata as they don't really are content scripts. These sandboxes won't execute any script. They will only be used to expose chrome/browser APIs to these iframes. Differential Revision: https://phabricator.services.mozilla.com/D234824
1 parent 43b67ab commit c0db8f7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

devtools/client/webconsole/test/browser/browser_webconsole_webextension_content_script.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ add_task(async function () {
2323

2424
files: {
2525
"content-script.js": function () {
26+
/* global browser */
2627
console.log("def");
28+
29+
// Create an iframe with a privileged document of the extension
30+
const iframe = document.createElement("iframe");
31+
iframe.src = browser.runtime.getURL(`iframe.html`);
32+
document.body.appendChild(iframe);
33+
2734
Promise.reject("abc");
2835
},
36+
37+
"iframe.html": `<div>Extension iframe</div> <script src="iframe.js"></script>`,
38+
"iframe.js": `console.log("iframe log"); throw new Error("iframe exception")`,
2939
},
3040
});
3141

@@ -37,6 +47,13 @@ add_task(async function () {
3747
await checkUniqueMessageExists(hud, "uncaught exception: abc", ".error");
3848
await checkUniqueMessageExists(hud, "def", ".console-api");
3949

50+
await checkUniqueMessageExists(hud, "iframe log", ".console-api");
51+
await checkUniqueMessageExists(
52+
hud,
53+
"Uncaught Error: iframe exception",
54+
".error"
55+
);
56+
4057
// Enable the content script preference in order to see content scripts messages,
4158
// sources and target.
4259
const onTargetProcessed = waitForTargetProcessed(

devtools/server/connectors/js-process-actor/target-watchers/content_script.sys.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ function createTargetsForWatcher(watcherDataObject, _isProcessActorStartup) {
131131
const sandboxes = lazy.ExtensionContent.getAllContentScriptGlobals();
132132
for (const contentScriptSandbox of sandboxes) {
133133
const metadata = Cu.getSandboxMetadata(contentScriptSandbox);
134-
if (metadata["browser-id"] != browserId) {
134+
// Ignore sandboxes without metadata which are related to the hack
135+
// of bug 1214658, which spawns content script sandboxes in order
136+
// to expose chrome/browser API to iframes loading extension documents.
137+
if (!metadata || metadata["browser-id"] != browserId) {
135138
continue;
136139
}
137140
createContentScriptTargetActor(watcherDataObject, {

0 commit comments

Comments
 (0)