tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_dbg-extension-inspectedWindow-debugger-statement.js (2414B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 // Test that web extensions' inspectedWindow.eval() doesn't break debugger/console
      6 
      7 "use strict";
      8 
      9 // Test debugger statement in page, with devtools opened to debugger panel
     10 add_task(async function () {
     11  const extension = await installAndStartExtension();
     12 
     13  const dbg = await initDebugger("doc-scripts.html");
     14 
     15  await extension.awaitMessage("loaded");
     16 
     17  info("Evaluating debugger statement in page");
     18  const evalFinished = invokeInTab("nestedC");
     19  await waitForPaused(dbg);
     20 
     21  info("resuming once");
     22  await resume(dbg);
     23 
     24  // bug 1728290: WebExtension target used to trigger the thread actor and also pause a second time on the debugger statement.
     25  // This would prevent the evaluation from completing.
     26  info("waiting for invoked function to complete");
     27  await evalFinished;
     28 
     29  await closeTabAndToolbox();
     30  await extension.unload();
     31 });
     32 
     33 // Test debugger statement in webconsole
     34 add_task(async function () {
     35  const extension = await installAndStartExtension();
     36 
     37  // Test again with debugger panel closed
     38  const toolbox = await openNewTabAndToolbox(
     39    EXAMPLE_URL + "doc-scripts.html",
     40    "webconsole"
     41  );
     42  await extension.awaitMessage("loaded");
     43 
     44  info("Evaluating debugger statement in console");
     45  const onSelected = toolbox.once("jsdebugger-selected");
     46  const evalFinished = invokeInTab("nestedC");
     47 
     48  await onSelected;
     49  const dbg = createDebuggerContext(toolbox);
     50  await waitForPaused(dbg);
     51 
     52  info("resuming once");
     53  await resume(dbg);
     54 
     55  await evalFinished;
     56 
     57  await closeTabAndToolbox();
     58  await extension.unload();
     59 });
     60 
     61 async function installAndStartExtension() {
     62  async function devtools_page() {
     63    await globalThis.browser.devtools.inspectedWindow.eval("");
     64    globalThis.browser.test.sendMessage("loaded");
     65  }
     66 
     67  const extension = ExtensionTestUtils.loadExtension({
     68    manifest: {
     69      devtools_page: "devtools_page.html",
     70    },
     71    files: {
     72      "devtools_page.html": `<!DOCTYPE html>
     73      <html>
     74       <head>
     75         <meta charset="utf-8">
     76       </head>
     77       <body>
     78         <script src="devtools_page.js"></script>
     79       </body>
     80      </html>`,
     81      "devtools_page.js": devtools_page,
     82    },
     83  });
     84 
     85  await extension.startup();
     86 
     87  return extension;
     88 }