Git Product home page Git Product logo

Comments (16)

villageitservices avatar villageitservices commented on August 22, 2024 1

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.

godd9170 avatar godd9170 commented on August 22, 2024

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.

tshaddix avatar tshaddix commented on August 22, 2024

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.

godd9170 avatar godd9170 commented on August 22, 2024

from webext-redux.

tshaddix avatar tshaddix commented on August 22, 2024

@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.

tshaddix avatar tshaddix commented on August 22, 2024

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.

tshaddix avatar tshaddix commented on August 22, 2024

If not, I'll be happy to. Feel free to blame me for everything!

from webext-redux.

godd9170 avatar godd9170 commented on August 22, 2024

from webext-redux.

tshaddix avatar tshaddix commented on August 22, 2024

Sounds great! Happy to help wherever you need it!

from webext-redux.

godd9170 avatar godd9170 commented on August 22, 2024

Ok I've taken a run at this and come up short. Here are my modifications to react-chrome-redux

godd9170@60f3ef0

And here is how I'm trying to implement it as a variant of your clicker-key example.

godd9170/clicker-key@8ee8dd4

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.

godd9170 avatar godd9170 commented on August 22, 2024

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.

tshaddix avatar tshaddix commented on August 22, 2024

Fixed in #49

from webext-redux.

MrBlenny avatar MrBlenny commented on August 22, 2024

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.

vhmth avatar vhmth commented on August 22, 2024

@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.

MrBlenny avatar MrBlenny commented on August 22, 2024

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.

vhmth avatar vhmth commented on August 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.