Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies & readme + bump version #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update dependencies & readme + bump version
Nacryn committed Jun 18, 2019
commit 46cd6a8e704089a6f579d96adb8c3edc9eb3c7a6
671 changes: 321 additions & 350 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "electron-better-web-request",
"version": "1.0.1",
"version": "1.0.2",
"description": "Module replacement for electron-web-request",
"main": "./lib/store.js",
"author": "Station <hello@getstation.com>",
"license": "ISC",
"homepage": "https://github.com/getstation/electron-better-web-request#readme",
"repository": {
"type" : "git",
"url" : "https://github.com/getstation/electron-better-web-request"
},
"type": "git",
"url": "https://github.com/getstation/electron-better-web-request"
},
"scripts": {
"test": "mocha -r ts-node/register test/**/*.ts",
"prepublish": "rm -rf ./lib/ && tslint -p . && tsc -p . --declaration"
@@ -18,15 +18,15 @@
"lib"
],
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.18",
"@types/mocha": "^5.2.7",
"@types/node": "^10.14.9",
"@types/uuid": "^3.4.4",
"electron": "^4.0.1",
"electron": "^4.2.4",
"mocha": "^5.2.0",
"ts-node": "^7.0.1",
"tslint": "^5.12.0",
"tslint": "^5.17.0",
"tslint-config-station": "^0.5.1",
"typescript": "^3.2.2"
"typescript": "^3.5.2"
},
"dependencies": {
"url-match-patterns": "^0.2.0",
12 changes: 9 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Electron Better Web Request

This module aims to extend the usage of `electron-web-request` by allowing to bind different listeners to the lifecycle events proposed by Electron. It aligns with the base usage found [here](https://electronjs.org/docs/api/web-request), but work around [this issue](https://github.com/electron/electron/issues/10478) by proposing a multi-listeners mechanism.
This module extends the usage of `electron-web-request`, allowing to bind different listeners to the lifecycle events proposed by Electron. It aligns with the base usage found [here](https://electronjs.org/docs/api/web-request), but work around [this issue](https://github.com/electron/electron/issues/10478) by proposing a multi-listeners mechanism.

It can be used as a drop-in replacement, and needs to be applied to `Electron.session` (override the default `webRequest`, see [usage](https://github.com/getstation/electron-better-web-request#usage)) to work identically. If used as is, it only uses the last registered listener for a method (retro-compatible). On top of that, the [API](https://github.com/getstation/electron-better-web-request#api) offers ways to add/remove listeners, give them context and define a custom merging strategy for all applicable listeners.
It can be used as a drop-in replacement, and needs to be applied to `Electron.session` (override the default `webRequest`, see [usage](https://github.com/getstation/electron-better-web-request#usage)) to work identically. **If used as is, it only uses the last registered listener** for a method (retro-compatible).

On top of that, the [API](https://github.com/getstation/electron-better-web-request#api) offers ways to add/remove listeners, give them context and define a custom merging strategy for all applicable listeners.

## Getting started

@@ -20,7 +22,7 @@ enhanceWebRequest(session)
```
Calling `enhanceWebRequest()` with the target `session` will override its `webRequest` with this module. From there, you can keep using it as usual, with all the new benefits.

*Note :* If you call `enchanceWebRequest` on a session that has already been enhanced, it does NOT override the module again, preserving all the listeners that you previously registered.
*Note :* If you call `enchanceWebRequest` on a session that has already been enhanced, it does NOT override the module again, preserving all the listeners that you previously registered.

**Basic drop in replacement**
```js
@@ -34,6 +36,8 @@ session.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
})
```

💡 The basic behavior uses only the last registered listener ! Implement your own merging strategy through resolvers to modify this.

**With merging strategy**
```js
const filter = {
@@ -66,6 +70,8 @@ session.webRequest.setResolver('onBeforeSendHeaders', (listeners) => {
return last.apply()
})
```
💡 The resolver implemented in this example is the one by default and resolve only to the last registered listener.

Check the `setResolver()` API details below to see what the array `listeners` is made of.

# API