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

[Question] can this be used for browser plugins? #116

Open
domdorn opened this issue Feb 20, 2020 · 1 comment
Open

[Question] can this be used for browser plugins? #116

domdorn opened this issue Feb 20, 2020 · 1 comment

Comments

@domdorn
Copy link

domdorn commented Feb 20, 2020

I'm currently developing a browser plugin for firefox.
As firefox (as well as chrome, etc.) has different scopes for the DOM of normal pages and the DOM accessed by the plugin, the plugin can only interact with the page through message passing (so no invocations on objects).. basically a perfect use case for Akka(.js).

Is it possible to spawn an ActorSystem in the scope of the page and one in the scope of the plugin and let them communicate?

@domdorn domdorn changed the title can this be used for browser plugins? [Question] can this be used for browser plugins? Feb 20, 2020
@domdorn
Copy link
Author

domdorn commented Feb 21, 2020

so my current approach would be something like this.. not sure if that actually works

  1. handle the actual tab
    1a) create a script that loads the scala.js and akka.js dependencies
    1b) create a script that creates an ActorSystem('akkabrowser') and bind it to something like window.akka.akkabrowser .
    1c) do a
document.addEventListener('akkabrowser', function(e) { 
val message = e.detail
ActorRef(message.destination).forward(message.payload, message.sender)(window.akka.akkabrowser)
})
  1. handle the foreground script in the extension
    2a) create a script that creates an ActorSystem('akkapluginfe') and bind it to something like window.akka.akkapluginfe
    2b) do a
document.addEventListener('akkapluginfe', function(e) { 
val message = e.detail
ActorRef(message.destination).forward(message.payload, message.sender)(window.akka.akkapluginfe)
})
  1. handle background scripts in the extension // TODO ..
  2. create some code similar to akka-remote that transforms a non-local message to something like
val envelope = ....
val targetActorSystem = extractActorSystem(envelope.destination)
val customEvent = new CustomEvent(targetActorSystem, {detail: {
  destination = envelope.destination
  payload = envelope.message
  sender = createAbsoluteSender(envelope.sender)
}}
document.dispatchEvent(customEvent);

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant