Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access window.ai from inside another extension #47

Open
JeroenvdV opened this issue Apr 28, 2023 · 6 comments
Open

Access window.ai from inside another extension #47

JeroenvdV opened this issue Apr 28, 2023 · 6 comments
Labels
good first issue Good for newcomers

Comments

@JeroenvdV
Copy link

JeroenvdV commented Apr 28, 2023

I'm working on a browser extension myself that could I would like to use window.ai as a backend. Unlike in a page, my injected js code currently can't access window.ai (in Chrome), because it remains undefined. Is there a way to access the API from an extension or what would be needed to enable that?

@alexanderatallah
Copy link
Owner

Are you injecting your script before the document load event? What happens if you wait for load and then try? Also, what happens if you use “npm i window.ai” and then await getWindowAI ?

@louisgv
Copy link
Collaborator

louisgv commented Apr 28, 2023

You will need to inject your CS inside the mainworld to be able to consume this API as-is. The default world content script (CS) lives in does not share the same window context as the main world (where window.ai exposes the API).

One way we can do is to add a secondary interface via externallyConnectable, so that other extension can call window.ai directly via extension messaging instead of having to pipe message from main -> their extension. This will also allow other extension to not be rely on the main world (which is only exposed when user visit a site).

Another way is to have window.ai be a central model config store (like a password manager). Since extension communication are not real time (or at least I don't recall there was an API for that :d...). Then, other extension can ask for the auth data from window.ai, and use a window.ai's client package that implement the API interface in their own extension, invoking the model however they like.

@alexanderatallah
Copy link
Owner

extension communication are not real time (or at least I don't recall there was an API for that :d...)
@louisgv what do you mean by this?

@JeroenvdV It sounds like making the extension externally connectable is the best path so far to making this easy, but in the meantime you can make a main world script. (e.g. With Plasmo:

export const config: PlasmoCSConfig = {
  matches: ["<all_urls>"],
  world: "MAIN",
  all_frames: true
}

Will close this for now but feel free to reopen if this doesn't work.

@louisgv
Copy link
Collaborator

louisgv commented Apr 30, 2023

@alexanderatallah by realtime I mean like the port API - I shoulda say -"long-lived" comms :d

@alexanderatallah
Copy link
Owner

Reopening this to mark a task for improving support for connecting from other extensions

@alexanderatallah alexanderatallah added the good first issue Good for newcomers label May 1, 2023
@YanniKouloumbis
Copy link
Collaborator

I will take a look at this tomorrow! I would love to see to some sort of Plasmo template that makes it easy to get started with window.ai in a chrome extension!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
No open projects
Status: Todo
Development

No branches or pull requests

4 participants