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

fix: content-webapp messaging with postMessage for firefox #33

Merged
merged 4 commits into from
Mar 19, 2023

Conversation

baruchiro
Copy link
Collaborator

  • content-webapp events with abstract function
  • use window.postMessage instead of custom event

See here, and I can't find the official documentation right now, but for security reasons, Firefox desn't allow to pass an object inside a CustomEvent between content-script and the host app.

You have to cloneInto it or something.

@baruchiro baruchiro added this to the 1.0.0 milestone Mar 16, 2023
@baruchiro baruchiro requested a review from jossef March 16, 2023 13:29
@baruchiro baruchiro self-assigned this Mar 16, 2023
@baruchiro baruchiro requested a review from GuyNachshon March 16, 2023 13:29
@@ -5,6 +5,13 @@ export const RESPONSE_PACKAGE_INFO_EVENT = overlayPrefix + 'RESPONSE_PACKAGE_INF
export const READY_EVENT = overlayPrefix + 'READY_EVENT';

export const dispatchEvent = (type, detail) => {
const event = new CustomEvent(type, { detail });
window.dispatchEvent(event);
window.postMessage({ type, detail }, '*');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the * part of a test or purposely there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A target origin can be specified using the targetOrigin member of options. If not provided, it defaults to "/". This default restricts the message to same-origin targets only.

I kept it as default, it is what we need.

@jossef jossef merged commit 8a45ff6 into master Mar 19, 2023
@jossef jossef deleted the firefox-messages branch March 19, 2023 07:59
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

Successfully merging this pull request may close these issues.

2 participants