-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add WebRequest API #7
Conversation
@alexstrat, right now the electrons api works well, tested with custom agent header. The cancel callback work also in the dummy extension Lulumi implementation: Chromium: API |
@alexstrat
WTF?
Tab console on the left and background console on the right... |
@alexstrat ready for a review. I've tried to abstract the RPC but it's not really necessary I think. We will add a lot of lines for the same behaviour. |
lib/common/constants.js
Outdated
@@ -36,6 +36,8 @@ constants.TABS_SEND_MESSAGE_RESULT_ = 'CHROME_TABS_SEND_MESSAGE_RESULT_'; | |||
constants.TABS_EXECUTESCRIPT = 'CHROME_TABS_EXECUTESCRIPT'; | |||
constants.TABS_EXECUTESCRIPT_RESULT_ = 'CHROME_TABS_EXECUTESCRIPT_RESULT_'; | |||
|
|||
constants.TABS_EXECUTESCRIPT_RESULT_ = 'CHROME_TABS_EXECUTESCRIPT_RESULT_'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
"permissions": [ | ||
"webRequest", | ||
"webRequestBlocking", | ||
"*://*/*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One day we'll need to handle this correctly :) one day
example/main.js
Outdated
urls: ['<all_urls>'] | ||
} | ||
|
||
session.defaultSession.webRequest.onResponseStarted(filter, (details) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
@alexstrat done |
lib/browser/api/web-request.js
Outdated
const fromChromeObjectToElectronObject = (details) => { | ||
if (details.responseHeaders) { | ||
const responseHeaders = []; | ||
Object.keys(details.responseHeaders).forEach((k) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array#map
;)
lib/browser/api/web-request.js
Outdated
if (cbReturn && cbReturn.responseHeaders) { | ||
const responseHeaders = {}; | ||
cbReturn.responseHeaders.forEach((header) => { | ||
return responseHeaders[header.name] = [header.value] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return
is confusing
} | ||
|
||
removeListener (callback) { | ||
const digest = callbackToDigest(callback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not sure why you need a callbackToDigest
This could not work here👇: const index = this.listeners.findIndex(cb => cb === callback);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edited
this.rpcManager = new RpcIpcManager(lib, this.rpcScopeRenderer); | ||
} | ||
|
||
handlerBehaviorChanged () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's now ddd a console.warning
when dummy-mock methods
lib/browser/api/web-request.js
Outdated
'onHeadersReceived', 'onAuthRequired', 'onResponseStarted', 'onBeforeRedirect', 'onCompleted', | ||
'onErrorOccurred']; | ||
|
||
const fromElectronObjectToChromeObject = (cbReturn) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: to be clear, I guess you can reduce the scope of this utility to only headers and rename it more precisely
…o fix/mixmax # Conflicts: # lib/browser/api/web-request.js
} | ||
} | ||
|
||
module.exports = ChromeWebRequestAPIHandler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: end of line
lib/browser/rc-event-controller.js
Outdated
this.controlerRPCScope = `${eventId}-controller`; | ||
this.eventRPCScope = `${eventId}-event`; | ||
|
||
this.rcpManager = new RpcIpcManager({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: type rpc
lib/renderer/extensions/rc-event.js
Outdated
try { | ||
return listener.call(this, args); | ||
} catch (e) { | ||
return e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather console.error
and return nothing, otherwise it'll try to pass it into callback on main's side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless electron-simple-rpc is smart enough to recognize it's an error.
However we don't care
One last non minor change and we're good to go ;) |
Todo
removeListener
hasListener