Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / dom / browser-element / BrowserElementChild.js
blob762957bcd4f7627690f2dac7f194977005e465d5
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 file,
3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* eslint-env mozilla/frame-script */
6 /* global api, CopyPasteAssistent */
8 "use strict";
10 function debug(msg) {
11   // dump("BrowserElementChild - " + msg + "\n");
14 var BrowserElementIsReady;
16 debug(`Might load BE scripts: BEIR: ${BrowserElementIsReady}`);
17 if (!BrowserElementIsReady) {
18   debug("Loading BE scripts");
19   if (!("BrowserElementIsPreloaded" in this)) {
20     Services.scriptloader.loadSubScript(
21       "chrome://global/content/BrowserElementChildPreload.js",
22       this
23     );
24   }
26   function onDestroy() {
27     removeMessageListener("browser-element-api:destroy", onDestroy);
29     if (api) {
30       api.destroy();
31     }
33     BrowserElementIsReady = false;
34   }
35   addMessageListener("browser-element-api:destroy", onDestroy);
37   BrowserElementIsReady = true;
38 } else {
39   debug("BE already loaded, abort");
42 sendAsyncMessage("browser-element-api:call", { msg_name: "hello" });