vulpemventures / marina

Liquid Wallet browser extension
MIT License
39 stars 19 forks source link

Add dispatchEvent for #installed and #updated #350

Closed tiero closed 2 years ago

tiero commented 2 years ago

This closes #337

Please @bordalix @huseyinsaritas review

tiero commented 2 years ago

marina-0.4.5.zip

bordalix commented 2 years ago

I think this will not work: background-script can't dispatch events to the browser tab, only content and inject script can.

I tried to add it to content and inject script, but it brings another issue: when an extension is updated, the extension context is invalidated, so the web app is still attached to the previous version of the extension. The events generated by the updated extension don't seem to go through.

I will keep trying to see if I can find a solution.

tiero commented 2 years ago

Good point, sorry to not have tested that.

What we can do then is maybe have the bg script to window.postMessage? then the content script can have a listener there for such message and dispatch the event? (like we do with the broker)

bordalix commented 2 years ago

Inject script already emits an event when injected (marina#initialized).

I'm doing some experiments on what can we achieve with it.

bordalix commented 2 years ago

I think this is simply not possible.

For the extension to be able to inform the web app it was installed or updated, the content script must be injected on the web app's DOM. But, accordingly to the manifest documentation [1], content scripts are only injected when the page (Document.readyState) emits one of these 3 events:

So, if a web app is fully loaded, and we install or update the extension, the content script will not be injected to the DOM, since none of these 3 events is emitted.

[1] See run_at here: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts