tshaddix / webext-redux

A set of utilities for building Redux applications in Web Extensions.
MIT License
1.23k stars 180 forks source link

runtime.connect() called from a webpage must specify an Extension ID #207

Closed alex-polunochev-zz closed 5 years ago

alex-polunochev-zz commented 5 years ago

webext-redux version 2.0.2 Chrome Version 74.0.3729.131 (Official Build) (64-bit)

Following the instructions from Readme. Configured the store in the background - can dispatch actions and can see store getting updated. Moving to the UI. Calling const store = new Store() from the content script injected to the webpage. It results in an error:

Screen Shot 2019-05-08 at 10 54 02 PM

or

Uncaught TypeError: Error in invocation of runtime.connect(optional string extensionId, optional object connectInfo): chrome.runtime.connect() called from a webpage must specify an Extension ID (string) for its first argument.
    at new Store (Store.js:86)

Looks like a reincarnation of https://github.com/tshaddix/webext-redux/issues/134

When as an experiment I pass the extension id (copied value from chrome://extensions tab) in as

const store = new Store({ extensionId: 'oqzqcvjbblablablablauwhodbbheeeuin' })

I am getting a different error:

Store.js:90 Uncaught TypeError: Cannot read property 'addListener' of undefined
    at new Store (Store.js:90)

Am I doing it right? Any clues?

alex-polunochev-zz commented 5 years ago

Based on this thread https://github.com/tshaddix/webext-redux/issues/47 I implemented an alternative communication channel using onMessageExternal, extensionId parameter for chrome.runtime.sendMessage and externally_connectable rule in manifest file. Now the messages go through. But without using Redux.

With the same manifest configuration the errors posted above still persist when I try to create new Store (with or without extensionId parameter).

@godd9170 could you share any additional information on what else you might have done to fix your problem (#47) besides what was published later in PR #49 and what I listed in the beginning of the post?

godd9170 commented 5 years ago

@alex-polunochev I'm afraid I don't remember much from that thread. I do know that #49 introduced everything I needed and passing that externalId allowed for communication from the .js that was injected into the page.

What do you mean exactly with But without using Redux?

alex-polunochev-zz commented 5 years ago

@godd9170 Thanks anyway! I meant there that finally I reached the point where my injected React component can send messages to background. But that unfortunately I wasn't able to use this library that brings Redux store and actions to facilitate a better, more efficient type of communication and storage.

tshaddix commented 5 years ago

Hey @alex-polunochev - sorry that you're having issues.

Have you tried removing this.extensionId from the call in store.js here? I'm wondering if the latest version of chrome does not like the "null" extension Id that we pass in the default props.

That said, I haven't seen the error on my side.

alex-polunochev-zz commented 5 years ago

@tshaddix I actually figured out the problem and should close this ticket, as there's no problem with webext-redux. I was using the 3rd party boilerplate code for my extension that was injecting the script into the hosting web page via a chain of calls which led to breaking of the execution context. Thus chrome.runtime was no longer providing an object to work with. After simplifying that execute-a-script-to-execute-a-script-to-inject-a-react-script flow and avoiding unneccessary steps, I managed to gain the control of the context back. Using webext-redux without problem now.

tshaddix commented 5 years ago

Excellent - great!