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

This script should only be loaded in a browser extension. #68

Open
addlistener opened this issue Sep 6, 2023 · 3 comments
Open

This script should only be loaded in a browser extension. #68

addlistener opened this issue Sep 6, 2023 · 3 comments

Comments

@addlistener
Copy link

addlistener commented Sep 6, 2023

image

webext-bridge 6.0.1

complaining code

import { sendMessage, onMessage } from "webext-bridge/content-script";

Possibly related to zikaari/crx-bridge#7 ? However no installation of webextension-polyfill or crx-polyfill are found

@zikaari
Copy link
Collaborator

zikaari commented Sep 25, 2023

You might be importing this in the wrong runtime, for example if this is being run in a script injected by content script - it won't work

@beautyfree
Copy link

You might be importing this in the wrong runtime, for example if this is being run in a script injected by content script - it won't work

Faced the same problem. Is there a way to make this work in an injected script?

@beautyfree
Copy link

Looks like I managed it.
Now I use webext-bridge/widnow in injected script

and don't forget about it:
https://github.com/zikaari/webext-bridge?tab=readme-ov-file#sendmessagemessageid-string-data-any-destination-string

Note: For security reasons, if you want to receive or send messages to or from window context, one of your extension's content script must call allowWindowMessaging(<namespace: string>) to unlock message routing. Also call setNamespace(<namespace: string>) in those window contexts. Use same namespace string in those two calls, so webext-bridge knows which message belongs to which extension (in case multiple extensions are using webext-bridge in one page)

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

3 participants