pulse-browser / browser

Pulse Browser: An experimental firefox fork
https://pulsebrowser.app/
Mozilla Public License 2.0
762 stars 44 forks source link

Content scripts are still broken in sidebars #251

Open trickypr opened 1 year ago

trickypr commented 1 year ago

As noted in #238, there are still a significant number of ads that are present in the sidebar. My best guess is that content scripts are not loading correctly because they are missing some supporting objects. Probably should look into these error messages:

WebExtension context not found! ExtensionParent.jsm:1296
    getContextById resource://gre/modules/ExtensionParent.jsm:1296
    recvAPICall resource://gre/modules/ExtensionParent.jsm:1133
    _recv resource://gre/modules/ConduitsChild.jsm:84
    receiveMessage resource://gre/modules/ConduitsParent.jsm:466
TypeError: browser is null BrowserElementParent.sys.mjs:21:21
    receiveMessage resource://gre/actors/BrowserElementParent.sys.mjs:21

Sidenote: linkhandler is throwing errors as well. Probably a good idea to think about fixing that

surapunoyousei commented 11 months ago

I found the way to allow run addon on web panel.

webpanelElem.setAttribute("src", "chrome://browser/content/browser.xhtml");
Services.prefs.setStringPref("floorp.browser.sidebar2.start.url", webpanelURL);
    // Browser Manager Sidebar embedded check
    let embedded = Services.prefs.getStringPref("floorp.browser.sidebar2.start.url");
    if (embedded != "" && embedded !== false && embedded != undefined) {
        if(gBrowser){
          loadBMSURI();
        } else {
          window.setTimeout(loadBMSURI, 1000);
        }
      }

    function loadBMSURI(){
      gBrowser.loadURI(Services.io.newURI(embedded), {
        triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
      });
      document.getElementById("main-window").setAttribute("chromehidden", "toolbar", "menubar directories extrachrome");
      document.getElementById("main-window").setAttribute("BSM-window", "true");
      Services.prefs.clearUserPref("floorp.browser.sidebar2.start.url");
      Services.prefs.setBoolPref("floorp.browser.sidebar2.addons.window.start", false);

      // Load CSS
      const BMSSyleElement = document.createElement("style");
      BMSSyleElement.textContent = `
         @import url("chrome://browser/content/browser-bms-window.css");
       `
      document.head.appendChild(BMSSyleElement);
    }
surapunoyousei commented 10 months ago

Briefly, chrome://browser/content/browser.xhtml is embedded as a browser window, and the window inside the web panel is recognized as a web panel window by using the pref condition classification.

This allows the add-on to run inside the web panel as if it were one more window.