Comments (16)
My work is not related to this rep. But it is a chrome extension too. I wasn't sure why I had to use onMessageExternal even though the content script and background script are from the same extension.Thanks for your help @godd9170
from webext-redux.
I think it might be as simple as adding in the extension id as the first parameter here: https://github.com/tshaddix/react-chrome-redux/blob/master/src/store/Store.js#L18
Would making an optional 'Extension Id' param to proxyStore
make this work? I'll give it a shot once I get a chance.
https://developer.chrome.com/extensions/runtime#method-connect
from webext-redux.
Hi there, @godd9170!
I'm thrilled to hear you enjoy this package!
I've definitely seen that error before... Is the content script you're communicating with owned by the same extension that is holding your background store?
from webext-redux.
from webext-redux.
@godd9170 Hmmm that's very interesting.
If the content script is owned by the same extension as the background page, the extension id should be optional according to the chrome docs.
The ID of the extension or app to connect to. If omitted, a connection will be attempted with your own extension. Required if sending messages from a web page for web messaging.
So I'm not sure why you're getting that error. Very odd. Do you mind posting some code where you instantiate the store in the background and the proxy store in the content script?
from webext-redux.
Ahhhh now I get it:
your .js in to the page's header
So your code is actually using web-messaging! Your call is coming from the webpage itself, not the content script owned by the extension, right?
Yes, I think we should allow a variable in the Store
options to take an extension id. Do you want to make a PR?
from webext-redux.
If not, I'll be happy to. Feel free to blame me for everything!
from webext-redux.
from webext-redux.
Sounds great! Happy to help wherever you need it!
from webext-redux.
Ok I've taken a run at this and come up short. Here are my modifications to react-chrome-redux
And here is how I'm trying to implement it as a variant of your clicker-key
example.
It seems like the messages just aren't being received in background.js. I'm trying the 'web-messaging' approach, added in the 'externally_connectable' bits to the manifest and no luck. The page errors when it tries to get the response from sendMessage
(https://github.com/godd9170/react-chrome-redux/blob/master/src/store/Store.js#L74).
Thoughts?
from webext-redux.
Ok so this is likely why... you've got to receive the messages differently
(https://developer.chrome.com/extensions/messaging#external-webpage)
chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
if (sender.url == blacklistedWebsite)
return; // don't allow this web page access
if (request.openUrlInEditor)
openUrl(request.openUrlInEditor);
});
Would adding the onMessageExternal
listener that is essentially a copy of the regular onMessage
be out of scope/break the package?
from webext-redux.
Fixed in #49
from webext-redux.
What is the status of this? I'm sufferting the same issue when trying to send messages through a script that I have injected into the page. Adding the extensionId
fixes the first issue, now I have an issue with sendMessage
because resp
is not defined.
chrome.runtime.sendMessage(_this3.extensionId, {
type: _constants.DISPATCH_TYPE,
portName: _this3.portName,
payload: data
}, function (resp) {
var error = resp.error,
Error in event handler for (unknown): TypeError: Cannot read property 'error' of undefined
from webext-redux.
@MrBlenny you mean that you can't connect normally from a script hosted/served from your extension? Do you have some minimal code example I can run to check this out?
from webext-redux.
The error only seemed to occur when the page does not have externally_connectable.matches
set in the manifest. I resolved this issue by manually sending a message using chrome.runtime.sendMessage
and only adding the proxy store if the chrome.runtime.sendMessage
gets a response.
from webext-redux.
@MrBlenny you shouldn't be able to send a message from a webpage to an extension without a externally_connectable
matches entry. From the docs:
If externally_connectable is not declared in your extension's manifest, all extensions and apps can connect, but no webpages can connect.
from webext-redux.
Related Issues (20)
- Hot reloading using yarn start leads to error - chrome.runtime.connect() called from a webpage must specify an Extension ID
- Ensure chrome api available before checking lastError
- Mozilla WebExtension-Polyfill support? HOT 3
- What is way to creating Chrome extention with default create-react-app?
- Cannot read properties of undefined (reading 'error') HOT 1
- Storyful is using webext-redux
- wrapStore tabs.query has extra argument
- "can't access dead object" while developing on Firefox
- saga middleware typescript problem
- Question: Advise for hot reloading in development HOT 1
- Doesn't work with react-redux v8 HOT 3
- Is manifest version 3 support planned? HOT 4
- How to fix Uncaught TypeError: Cannot read properties of undefined (reading 'state') HOT 7
- Data not persisting HOT 2
- React Redux State updated value not showing on page refresh
- Is this repo still actively maintained & supported?
- middleware warning when using rtk-query
- useselector not working despite providing store HOT 1
- How to re-sync store from "content script" with background.js (service worker)? HOT 2
- Cannot install webext-redux next to react-redux
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webext-redux.