tshaddix / webext-redux

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

Cannot read properties of undefined (reading 'error') #269

Closed fredericrous closed 2 years ago

fredericrous commented 2 years ago

The extension I'm working on freezes randomly with the current error message:

Unchecked runtime.lastError: The message port closed before a response was received.
Error handling response: TypeError: Cannot read properties of undefined (reading 'error')
    at chrome-extension://gloenokcpppknddegfmmopacmbfbfdlh/contentScript.bundle.js:48:13164

When I click on the file name, I see the related (minimified) code is

{
                    key: "dispatch",
                    value: function(e) {
                        var t = this;
                        return new Promise((function(n, i) {
                            t.serializedMessageSender(t.extensionId, {
                                type: a.DISPATCH_TYPE,
                                portName: t.portName,
                                payload: e
                            }, null, (function(e) {
                                var t = e.error
                                  , a = e.value;
                                if (t) {
                                    var o = new Error("".concat("\nLooks like there is an error in the background page. You might want to inspect your background page for more details.\n").concat(t));
                                    i((0,
                                    r.default)(o, t))
                                } else
                                    n(a && a.payload)
                            }
                            ))
                        }
                        ))
                    }
                },

It looks like the Issue comes from this line https://github.com/tshaddix/webext-redux/blob/8e9aeee8144d476290feb75ae10c823a341080bf/src/store/Store.js#L160

My guess is that we should check if resp is defined and if it is undefined we should check the error coming from runtime.lastError

tshaddix commented 2 years ago

Fix released in 2.1.8

Thanks for the contribution!