tfoxy/chrome-promise

New chrome errors when accessing extension.sendRequest, extension.onRequest, or extension.onRequestExternal

Quantumplation opened this issue · 5 comments

Hello!

This extension has been super useful for me so far.

However, a new version of chrome (I'm on Version 71.0.3578.98) seems to throw an error whenever accessing the properties sendRequest, onRequest, or onRequestExternal on the "extension" object.

This means that the code here:

if (hasOwnProperty.call(source, key)) {
          var val = source[key];

is causing this node module to throw an error, and the chrome plugin can't proceed. The exact error (in my case) is below:

background.js:592 Uncaught Error: extension.sendRequest, extension.onRequest, and extension.onRequestExternal are deprecated. Please use runtime.sendMessage, runtime.onMessage, and runtime.onMessageExternal instead.
    at fillProperties (background.js:592)
    at fillProperties (background.js:597)
    at new ChromePromise (background.js:547)
    at Object../node_modules/chrome-promise/index.js (background.js:634)
    at __webpack_require__ (background.js:20)
    at Object../app/extension/scripts/background.ts (background.js:107)
    at __webpack_require__ (background.js:20)
    at Object.0 (background.js:2178)
    at __webpack_require__ (background.js:20)
    at background.js:84

I'm happy to submit a pull request later today. I can think of two approaches to handling this:

  • Wrap the var val = source[key] property in a try-catch block, and skip properties that are now error-deprecated
  • create a hard-coded black-list of properties that are skipped no matter what.

Any preference as to which approach I take?

(If I don't hear from you in the next few hours, I'll submit a PR with the first approach, given that that future proofs against other issues of this kind)

tfoxy commented

Hi!

The PR is welcome. I think the first approach is better. I try to avoid hard-coding things in this library.

Temporary solution.
Change "chrome-promise": "^3.0.2", to
"chrome-promise": "git+https://github.com/andy265/chrome-promise.git", and run npm i.

tfoxy commented

Thanks @andy265 !

Another solution for a PR would be to lazily load the APIs by using getters. This way there would be no error until you access a deprecated API, just like when using the chrome object.

tfoxy commented

Fixed in v3.0.3!