Skip to content

Tracking issue: //extensions integration #19447

Closed

Description

@nornagon

This is a tracking issue for the work remaining to migrate our Chrome Extensions support away from our ad-hoc polyfills to the official //extensions code in Chromium.

Activity

  1. nornagon commented on Jul 25, 2019

    @nornagon
    ContributorAuthor

    Building on the API that @samuelmaddock suggested in #17440, here's a draft to be evolved as requirements become evident.

    interface Extension {
      id: string,
      path: string,
      manifest: chrome.Manifest
    }
    
    class Session {
      /** Emitted when extension is installed and ready. */
      on(event: 'extension-ready', listener: (event: Event, extension: Extension) => void): this;
    
      /** Loads an extension from the filesystem.
       * The returned promise is fulfilled when the extension has been successfully loaded,
       * or rejected with an error if the extension could not be successfully loaded.
       */
      loadExtension(path: string): Promise<Extension>;
      removeExtension(extensionId: string): void;
      enableExtension(extensionId: string): void;
      disableExtension(extensionId: string): void;
    
      getExtension(extensionId: string): Extension;
      getAllExtensions(): Extension[];
    }
  2. nornagon commented on Jul 26, 2019

    @nornagon
    ContributorAuthor

    To remove in the new world:

    • BrowserWindow.addDevToolsExtension
    • BrowserWindow.removeDevToolsExtension
    • BrowserWindow.getDevToolsExtensions

    //extensions doesn't distinguish between devtools extensions and non-devtools extensions. We can deprecate these functions and delegate them to defaultSession.loadExtension &c. to avoid breaking users without warning.

    • BrowserWindow.addExtension
    • BrowserWindow.removeExtension
    • BrowserWindow.getExtensions

    Extensions are session-specific, so these APIs should move to Session. We can deprecate these functions and delegate them to the default session in the interim.

  3. sentialx commented on Jul 28, 2019

    @sentialx
    Contributor

    @nornagon How chrome.tabs related functions will be handled? Could I listen for example to chrome.tabs.create? I suggest adding for example a extensions-tabs-create event which is fired when an extension calls a chrome.tabs.create function to the Session class. Also, I've been implementing my own extensions system and I think that the extensionsRenderer object might be interesting for you as it handles UI related events such as the aforementioned API or chrome.browserAction.onClicked etc.

  4. nornagon commented on Jul 29, 2019

    @nornagon
    ContributorAuthor

    A lot of the chrome.tabs APIs don't make a lot of sense in an Electron context (e.g. chrome.tabs.getAllInWindow), so I don't think it makes sense for us to implement the full API. In general we aren't aiming to support every Chrome extension, only just enough to support the most common use cases (in particular, devtools extensions like React Devtools, and the internal PDF viewer extension). We probably want to make sure it's possible for apps to add custom implementations for APIs we don't support, e.g. through preload scripts.

    Do you have a particular use-case in mind for the chrome.tabs.create API?

  5. sentialx commented on Jul 29, 2019

    @sentialx
    Contributor

    I'm making a web browser with multi-window and tabs support, so it would be nice to at least extend the chrome apis in background and content scripts.

  6. sentialx commented on Jul 29, 2019

    @sentialx
    Contributor

    @nornagon What bothers me now is how injecting preload scripts into the background pages would work? Will be there a session.setBackgroundPreloads API or something? Also, content scripts execute in isolated worlds, so how would I know in which world there's a chrome object?

  7. nornagon commented on Jul 29, 2019

    @nornagon
    ContributorAuthor

    Yes, it should be possible to inject preload scripts into background pages. session.setPreloads should do it. I think the easiest way to extend our current preload API would be to add a way for a preload script to know what kind of world it's being injected into (e.g. a global.electron.worldType variable or similar). Ideally we'd extend the preload API so you could specify a different script for each world type.

  8. kinop112365362 commented on Aug 6, 2019

    @kinop112365362

    Is there a guide to participating in the contributing code, about Google's extensions? @nornagon

  9. MarshallOfSound commented on Jan 14, 2020

    @MarshallOfSound
    Member

    What happens if you load the same extension id with a different version, does it replace the old one, or fail, or something else ❓

  10. sentialx commented on Jan 17, 2020

    @sentialx
    Contributor

    Is there a list of supported chrome APIs in the new extensions implementation?

  11. nornagon commented on Jan 17, 2020

    @nornagon
    ContributorAuthor

    Not yet but there should be! So far I think the list is something like:

    • chrome.runtime.*
    • chrome.extension.getURL (and maybe a couple of other chrome.extension APIs?)
    • chrome.tabs.executeScript - limited support, requires specifying tabId
    • chrome.tabs.sendMessage
    • chrome.devtools.* for devtools extensions
    • chrome.storage.local.*

    this is just off the top of my head though, I think that there are quite a few more that may be supported already (e.g. i think most of the things in this list should work?) and there may be some restrictions on some of these APIs that I don't recall. I'll do a more thorough investigation soon and add this list to the docs at some point.

    Ultimately though, we are not interested in maintaining anything close to feature parity with Chrome extensions. Our goal is to support devtools extensions (which we already do to some extent, so this will be maintaining roughly the same level of support) and to enable internal extensions like the PDF viewer. There are many concepts in Chrome's extensions API which do not map well to Electron—things like tabs, windows, the omnibox, sync profiles and so on—and it would be far too much effort to hook and expose all of these to app authors.

  12. sentialx commented on Jan 17, 2020

    @sentialx
    Contributor

    @nornagon Thanks for your great and hard work on it! I would be very grateful if chrome.extension.getBackgroundPage and chrome.extension.getViews would be also supported since it's very hard to actually implement this in JS by using only IPC. Or I would also appreciate if you could at least guide me how these APIs could be implemented.

  13. nornagon commented on Jan 17, 2020

    @nornagon
    ContributorAuthor

    those seem plausibly doable! i'll look into it.

  14. spikecodes commented on Jan 18, 2020

    @spikecodes

    Super excited about this!

  15. samuelmaddock commented on Jan 20, 2020

    @samuelmaddock
    Member

    cc @sentialx @alexstrat @stewartlord @Thomas101

    There are potentially breaking changes being introduced with the planned deprecation of Electron's current extension support in #21812. Projects adding additional Chrome APIs using the existing extensions implementation would likely cease to function.

    I alerted @nornagon to this problem and he mentioned investigating whether it would be possible to support both implementations.

    As far as I know, @nornagon is the only contributor actively working on the new extensions system implementation. Based on his work in #21779, it would likely be a considerable effort to support all Chrome APIs. I would encourage folks with an interest in this to start investigating solutions using the new extensions system.

  16. 34 remaining items

  17. sentialx commented on Mar 7, 2020

    @sentialx
    Contributor

    There must not be the necessary hooks setup for this API to work yet.

    I noticed that the web_request.json file is missing. Maybe that's the problem?

  18. samuelmaddock commented on Mar 7, 2020

    @samuelmaddock
    Member

    I noticed that the web_request.json file is missing. Maybe that's the problem?

    The base //extensions implementation provides some APIs out of the box, web_request.json is one of those. We'll need to search through the chrome codebase to see how it's interacting with the webRequest API, then do the same in electron.

  19. sentialx commented on Mar 7, 2020

    @sentialx
    Contributor

    I've found this to happen when not loading a directory containing a manifest.json file. If there's a version subdirectory within extensions\aeblfdkhhhdcdjpifhhbdiojplfjncoa, try loading that directly.

    Unfortunately, there's a problem with their background.js causing Electron to crash. When I removed the file from manifest.json, it worked. I can't tell what's wrong with the file since it's uglified and big.

    EDIT: Sorry, that's not a problem with the JS file, but it seems that Electron doesn't support multiple background scripts. If I remove one, it works.

      "background": {
        "scripts": [
          "background/x.js",
          "background/background.js"
        ]
      },
  20. sentialx commented on Mar 7, 2020

    @sentialx
    Contributor

    Sometimes I get an error related to the messaging:

    Unchecked runtime.lastError: The message port closed before a response was received.
    

    For example in the Tampermonkey popup page, which also doesn't really display. The scripts load but nothing adds to the popup's <body>.

    image

  21. mitermayer commented on Apr 13, 2020

    @mitermayer

    What are the remaining blockers for this issue? Would love to contribute in any way to help push this along

  22. samuelmaddock commented on Apr 13, 2020

    @samuelmaddock
    Member

    @mitermayer this work is available in v9.x.y. Basic unpacked extensions can be loaded into a session. However, not all extension APIs are available or function properly. @sentialx and I have been contributing recently to fix some of these issues.

    Since Electron applications aren't constrained to the same tabbed browser model as traditional web browsers, some APIs such as chrome.tabs are intentionally left incomplete.

    There are a few projects made to fill this gap:

    If you're looking to use any extension in the Chrome webstore, there's still much work to be done. And as @nornagon mentioned, this will fall outside of officially maintained support.

  23. sentialx commented on Apr 13, 2020

    @sentialx
    Contributor

    @mitermayer
    I don't know the official "stable blockers" described by the Electron team, but for me and probably for anyone who wants to support Chrome extensions in their app is:

    • no session property in the e.sender object received through an ipc message, it makes it impossible to identify the session when messaging
    • crash when loading for example 1Password X and probably many others
    • no way to add additional properties to Tab object like selected or highlighted.

    The rest can be implemented easily in JS.

  24. nornagon commented on Apr 13, 2020

    @nornagon
    ContributorAuthor

    To clarify, it is not the intention of the Electron team to support loading arbitrary extensions from the Chrome Web Store. Our main goals with this effort are to:

    1. Reduce our maintenance burden by aligning with Chrome's architecture,
    2. Maintain & improve support for devtools extensions, and
    3. Provide a more solid base on which app developers can build.

    I think we still have some work to go with (3), but since supporting non-devtools extensions is a new feature, a few rough edges there aren't a stable blocker for us.

  25. sentialx commented on Apr 25, 2020

    @sentialx
    Contributor

    Another thing that makes it difficult are CORS errors when extensions are trying to do an XHR request.
    image

    I made a temporary workaround here.

  26. GoldSmyth commented on Nov 4, 2020

    @GoldSmyth

    Hi, I'm trying to find a way to activate the 'chrome.runtime' within the Electron browser, currently the chrome object is empty.

    Could somebody advise on the best way to do this?

    edit: I read above that I need to load an extension, could I load in the cryptoTokenExtension that comes bundled in Chrome? is there a way to import that?

    Any help appreciated

    Electron v9.3.1 Chrome v83.0.4103.122

  27. GoldSmyth commented on Nov 4, 2020

    @GoldSmyth
  28. corysimmons commented on Nov 9, 2020

    @corysimmons

    Bump?

  29. nornagon commented on Nov 10, 2020

    @nornagon
    ContributorAuthor

    I'm closing this as extensions support has landed and seems to be working fairly well, and as such there's not much use for a general-purpose tracking issue any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions