tor-browser

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

WebDriverDocumentInsertedChild.sys.mjs (1556B)


      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 const lazy = {};
      6 
      7 ChromeUtils.defineESModuleGetters(lazy, {
      8  getBrowsingContextDetails:
      9    "chrome://remote/content/shared/messagehandler/transports/BrowsingContextUtils.sys.mjs",
     10  Log: "chrome://remote/content/shared/Log.sys.mjs",
     11  truncate: "chrome://remote/content/shared/Log.sys.mjs",
     12 });
     13 
     14 ChromeUtils.defineLazyGetter(lazy, "logger", () => lazy.Log.get());
     15 
     16 export class WebDriverDocumentInsertedChild extends JSProcessActorChild {
     17  actorCreated() {
     18    lazy.logger.trace(
     19      `WebDriverDocumentInsertedChild actor created for PID ${Services.appinfo.processID}`
     20    );
     21  }
     22 
     23  observe = async (subject, topic) => {
     24    if (topic === "initial-document-element-inserted") {
     25      const window = subject?.defaultView;
     26      // Ignore events without a window (such as from SVG documents).
     27      if (!window) {
     28        return;
     29      }
     30      const context = window.browsingContext;
     31      const url = window.document.URL;
     32      const payload = {
     33        contextDetails: lazy.getBrowsingContextDetails(context),
     34        url,
     35      };
     36 
     37      try {
     38        this.sendAsyncMessage(
     39          "WebDriverDocumentInsertedChild:documentInserted",
     40          payload
     41        );
     42      } catch {
     43        lazy.logger.trace(
     44          lazy.truncate`Could not send WebDriverDocumentInsertedChild:documentInserted for URL: ${url}`
     45        );
     46      }
     47    }
     48  };
     49 }