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

calling 'onBeforeRequest' callback from nodejs side #1

Open
disovi opened this issue Jun 21, 2017 · 12 comments
Open

calling 'onBeforeRequest' callback from nodejs side #1

disovi opened this issue Jun 21, 2017 · 12 comments
Assignees
Labels

Comments

@disovi
Copy link

disovi commented Jun 21, 2017

I want to make some processing of 'details' on nodejs side and then decide whether I want to cancel that request or not. It is only possible to access details through 'onBeforeRequest' event now. But there is no access to 'callback' inside that event. Is it possible to add such functionality? If yes, can you give me a hint how to achieve this? thanks.

@kuraga
Copy link

kuraga commented Jul 28, 2017

@disovi @kyungw00k don't you know what is accessible in listener (onBeforeRequest callback)? What's the scope?

@disovi
Copy link
Author

disovi commented Jul 28, 2017

@kuraga scope is limited exact to function inner context. Listener function is stringified before being sent to electron.

@kuraga
Copy link

kuraga commented Jul 28, 2017

@disovi here ? So, this == {}?

@disovi
Copy link
Author

disovi commented Jul 28, 2017

@kuraga unfortunately yes. I've described a possible solution in linked issue, but you need some knowledge in electron-nightmare ipc connection to implement it.

@kuraga
Copy link

kuraga commented Jul 29, 2017

@kyungw00k @disovi can we change {} to { 'win': win }, etc.? Или мы не можем передавать эти объекты на ту сторону, @disovi ? If no, which objects could we point there?

@kyungw00k
Copy link
Owner

@disovi

I want to make some processing of 'details' on nodejs side and then decide whether I want to cancel that request or not.

As far as I know, if you want to cancel the specific request, you can filter the request by filtering url on detail object which passing to the first argument of the callback callback function.

For example, If you want to cancel the specific request,

const filter = {
  urls: ['https://*.github.com/*', '*://electron.github.io']
}

nightmare.onBeforeRequest(filter, function (details, callback) { /* Electron-side scope */
        /* POINT #1 */
        callback({cancel: true})
})

I guess the point of this question is handing details object with the NodeJS-side scope in POINT #1, right?

@kuraga

can we change {} to { 'win': win }, etc.?

Even if we change code {} to { 'win': win }, it still under the electron-side scope.

The callback we provide in NodeJS-side is want to access win object in the Electron-side,
then it can be possible.

@kuraga
Copy link

kuraga commented Aug 1, 2017

@kyungw00k we want to have read access to a copy of NodeJS-side object.

My task is different compared to @disovi 's: I want to set HTTP headers from file content.

@kyungw00k
Copy link
Owner

kyungw00k commented Aug 2, 2017

@kuraga

we want to have read access to a copy of NodeJS-side object.

If your NodeJS-side object can be serializable, I think it possibly can be read from Electron-side callback with a some modification of this addon.

But it would be the different issue from this issue, right?

@disovi
Copy link
Author

disovi commented Aug 2, 2017

I guess the point of this question is handing details object with the NodeJS-side scope in POINT #1, right?

@kyungw00k you are right. The idea was to use adblock extension together with nightmare. Unfortunately electron doesn't support chrome extensions. But there is an npm package Brave Adblock which implements this functionality. So basically I wanted to combine this engine with nightmare in onBeforeRequest callback.

@kuraga
Copy link

kuraga commented Aug 3, 2017

But it would be the different issue from this issue, right?

@kyungw00k , right 😄 @disovi , sorry! I'll create an issue.

@kyungw00k
Copy link
Owner

@disovi

But there is an npm package Brave Adblock which implements this functionality.

I've been looking the part which of the code had implemented the functionality from the Brave Adblock project, but I couldn't.

Could you do that for me?

@disovi
Copy link
Author

disovi commented Aug 14, 2017

@kyungw00k in their github-page sample:
var b1 = client.matches('http://www.brianbondy.com/public/ad/some-ad', FilterOptions.script, 'slashdot.org')
The first param - url, the third one is the host name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants