Commit Graph

30 Commits

Author SHA1 Message Date
Derrick Hammer 5ab05945cd Revert "*Move api data"
This reverts commit b39d81d20c.
2022-03-26 18:45:20 -04:00
Derrick Hammer b39d81d20c *Move api data 2022-03-26 18:23:24 -04:00
Derrick Hammer 14e23759c6 *Fix apiMetadata 2022-03-23 21:14:21 -04:00
Derrick Hammer 1f7f73c23b *Remove chrome.runtime check and namespace the package 2022-03-23 20:58:46 -04:00
Federico Brigante 780518ed1d
fix: enable webextension-polyfill usage via webpack ProvidePlugin (#351)
* Enable usage via `ProvidePlugin`
* Use `globalThis`
* Update lint to forbid `browser` global usage
2022-01-18 21:12:53 +01:00
Luca Greco 5ab825b83f
fix: Reject with real Error instances like Firefox does (#293)
Co-authored-by: Federico Brigante <me@fregante.com>
2021-03-18 18:07:16 +01:00
Doug Parker 716c90bca4 fix: wrap `onRequestFinished` to use promises
Fixes #249.

This updates `browser.devtools.network.onRequestFinished` to emit an
object with a promisified `getContent()` property. This brings the
polyfill implementation in line with Firefox's implementation, although
MDN documentation is still inaccurate at the moment.

Also updates some out of date documentation with `makeCallback()` and
`wrapAsyncFunction()`.
2020-12-10 23:08:57 +01:00
Manvel Saroyan 87bdfa844d fix: Added missing chrome privacy api settings (#205) 2019-11-21 15:21:06 +01:00
Rob Wu ad207a84b9
fix: Throw error when loaded in non-extension contexts (#190)
Fixes #186
2019-07-18 15:21:49 +02:00
Luca Greco 6f178c56da
fix: browser.devtools.inspectedWindow.eval promise should always resolve to an array (#175)
* fix: browser.devtools.inspectedWindow.eval promise should always resolve to an array
* test(integration): Add test for browser.devtools.inspectedWindow.eval API
2019-02-01 08:38:35 +01:00
Luca Greco cdbb3115e8 chore: Small tweaks to the eslint config files (follow-up for #167) 2019-01-28 18:56:40 +01:00
ExE Boss 83ec9e70ad test(integration): Use node for running test scripts (#167)
* test(integration): Use node for running browser smoketests
* test(integration): Use node for running test scripts
2019-01-28 18:49:25 +01:00
ExE Boss 7b46d25db2 refactor: Make the `wrapAPIs` function take the `chrome` object as a parameter (#139) 2018-08-27 15:50:40 +02:00
Luca Greco ebd28186a1
fix: Prevent a webpage document element to be detected as the Extension API object (#153) 2018-08-15 22:33:37 +02:00
ExE Boss 26683389ea
chore: Replace post-processed warning message with single-line string literal (#152) 2018-07-27 17:37:29 +02:00
Rob Wu d77a418537 feat: Support promises in privacy namespace 2018-07-11 18:04:32 +02:00
PoziWorld ea82fbf556 chore: Fixed typos in inline comments (#144) 2018-07-07 17:44:19 +02:00
Rob Wu d612352bba fix: resolve to undefined instead of an empty array 2018-07-04 13:17:09 +02:00
Simon Lydell 4e1e98add2 fix: sendMessage promise should resolve to undefined when no listeners reply 2018-07-04 13:06:42 +02:00
Luca Greco 6c8268f6fb feat: Reject sendMessage returned promise when a onMessage listener returns a rejected promise. 2018-06-02 20:59:46 +02:00
Luca Greco 831e355650 fix: print a deprecation warning when sendResponse callback is used for the first time 2018-06-02 20:59:46 +02:00
Luca Greco 76eeeaccc9
feat: Added support for the sendResponse callback in the runtime.onMessage listeners (#97) 2018-05-14 20:38:21 +02:00
Gerben 596f47bcc8 chore: Improve "fallback to no callback" wrapper.
According to review comment https://github.com/mozilla/webextension-polyfill/pull/59/files#r142001949
2018-03-13 14:27:22 +01:00
Luca Greco 917ed413f6 fix: Add a new fallbackToNoCallback metadata property to customize the pageAction.show/hide wrappers behavior 2018-03-13 14:27:22 +01:00
Rob Wu 67b3780d38 fix: Lazily initialize API via the original target (#71)
Originally, the polyfill created a Proxy with the original API object as
the target. This was changed to `Object.create(chrome)` because not
doing so would prevent the `browser.devtools` API from working because
the devtools API object is assigned as a read-only & non-configurable
property (#57).

However, that action itself caused a new bug: Whenever an API object
is dereferenced via the `browser` namespace, the original API is no
longer available in the `chrome` namespace, and trying to access the
API through `chrome` returns `undefined` plus the "Previous API
instantiation failed" warning (#58).
This is because Chrome lazily initializes fields in the `chrome`
API, but on the object from which the property is accessed, while
the polyfill accessed the property through an object with the
prototype set to `chrome` instead of directly via chrome.

To fix that, `Object.create(chrome)` was replaced with
`Object.assign({}, chrome)`. This fixes both of the previous issues
because
1) It is still a new object.
2) All lazily initialized fields are explicitly initialized.

This fix created a new issue: In Chrome some APIs cannot be used even
though they are visible in the API (e.g. `chrome.clipboard`), so
calling `Object.assign({}, chrome)` causes an error to be printed to
the console (#70).

To solve this, I use `Object.create(chrome)` again as a proxy target,
but dereference the API via the original target (`chrome`) to not
regress on #58.
Besides fixing the bug, this also reduces the performance impact
of the API because all API fields are lazily initialized again,
instead of upon start-up.

This fixes #70.
2018-03-12 19:23:28 +01:00
Luca Greco 47ddfbfddb fix: Prevent 'Previous API instantiation failed' errors on runtime.sendMessage API calls (#64) 2017-10-11 15:51:43 +02:00
Luca Greco 61d92ea79b feat: Added devtools.inspectedWindow.eval and devtools.panels.create to wrapped APIs.
To be able to wrap the devtools API namespaces, this patch applies the
following changes:

- fix: Prevent Proxy violation exception on the read-only/non-configurable devtools property
  by using an empty object with the `chrome` API object as its prototype
  as the root Proxy target (the Proxy instances returned for the
  `chrome` API object) and add a related test case.

- fix: Added support for a new `singleCallbackArg` metadata property,
  which prevents devtools.panels.create to resolve an array of
  parameters (See the related Chromium issue at
  https://bugs.chromium.org/p/chromium/issues/detail?id=768159)
  and add the related test cases.

- test: Changes to the test case related to proxy getter/setter behavior
  on non wrapped properties:

  in the "deletes proxy getter/setter that are not wrapped" test case from
  the "test-proxied-properties.js" test file, we ensure that when a
  getter/setter is called for a "non-wrapped" property, the getter/setter
  is going to affect the original target object, unfortunately this in
  not true anymore for the root object (the `chrome` API object) because
  we are using an empty object (which has the `chrome` API object as its
  prototype and it is not exposed outside of the polyfill sources)
  as the target of the Proxy instance related to it,
  this change to the target of the Proxy has been needed to prevent the
  TypeError exception raised by the Proxy instance when we try to access
  the "devtools" property (which is non-configurable and read-only on the
  `chrome` API object).
2017-09-25 22:20:07 +02:00
Luca Greco 31d778c2cd fix: Changes to the UMD built file and npm package publishing
This patch introduces on top of #17 some minor changes from the
review comments, in particular:

- do not replace require("../filename") to include the api-metadata.json
  (restored the original '{/* include("...") */}' placeholder)
- raise an appropriate error message when the source file is used
  by mistake (or the "dist/" file has not been built correctly).
- set the generated UMD wrapped module as the package.json main
  entrypoint
- do not include api-metadata.json and src dir from the files included
  in the published npm package
- run both build and test npm scripts on prepublish
2017-04-11 14:16:15 +02:00
Joseph Frazier f9248e62e7 feat: library wrapped as an UMD module
This addresses [issue 7] by making it possible for users to run:

```sh
npm install webextension-polyfill
```

and download a module that they can use with a bundler as follows:

```js
import browser from 'webextension-polyfill';
```

Also, add a [prepublish script] so that users who clone the repo don't
need to run `grunt` manually. In addition, specify [files] in
package.json so that this module can be published to npm without
including miscellanea. This can be verified by running:

```sh
npm pack && tar -tvf webextension-polyfill-0.1.0.tgz
```

[issue 7]: https://github.com/mozilla/webextension-polyfill/issues/7
[files]: https://docs.npmjs.com/files/package.json#files
[prepublish script]: https://docs.npmjs.com/misc/scripts
2017-04-11 13:32:31 +02:00
Luca Greco d1b0ff929a fix: rename polyfill source into src/browser-polyfill.js 2016-11-07 16:56:48 +01:00