Skip to content

Proxied requests cannot be aborted #332

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

Open
tbardiuk-ua opened this issue Jan 23, 2023 · 4 comments
Open

Proxied requests cannot be aborted #332

tbardiuk-ua opened this issue Jan 23, 2023 · 4 comments

Comments

@tbardiuk-ua
Copy link

Hi guys. I'm trying to reduce traffic usage by not loading images. However, it seems that intercepted requests cannot be aborted when a proxy is used.

Here's an example:

browser = Ferrum::Browser.new(headless: false)
browser.network.intercept
browser.on(:request) do |request|
  if request.resource_type == 'Image'
    request.abort
  else
    request.continue
  end
end

browser.go_to('https://bing.com')

The result is a page with no images loaded, so everything works as expected. But if I just change the browser options by adding a proxy, all the images will load:

browser = Ferrum::Browser.new(proxy: { host: 'host.com', port: '80', user: 'username', password: 'password' }, headless: false)

I also checked if the on(:request) block is executed at all, and yes, it is. But request.abort doesn't seem to do anything.

Does anyone have any idea why this is happening and how to fix the problem?

Thanks in advance.

@olegp
Copy link

olegp commented Apr 30, 2023

I enabled logging and found out that the problem is with this line, which calls continue on an intercepted request before we call abort. As a result, when we call abort, we get back an "Invalid state for continueInterceptedRequest" error.

Until this is fixed, the workaround is to do the following:

browser = Ferrum::Browser.new(proxy: { host: 'host.com', port: '80' }, headless: false)
browser.network.authorize(user: 'username', password: 'password', type: :proxy) {}
browser.network.intercept
browser.on(:request) do |request|
  if request.resource_type == 'Image'
    request.abort
  else
    request.continue
  end
end

browser.go_to('https://bing.com')

This ensures that the line I linked to isn't called, while still enabling authorization, but passing through an empty block to authorize that doesn't call request.continue.

@route
Copy link
Member

route commented May 20, 2023

Thank you guys for reporting and for findings, I’ll get back to you after investigation

@danest
Copy link

danest commented Jul 27, 2024

I ran into this issue as well with proxies. Thank you for the tip on how to solve it

@glennpjones
Copy link

glennpjones commented Oct 16, 2024

@danest could you make it work using the same workaround? For me both this approach, and the request filtering directly within the authorize block (as mentioned in the readme) seem to do absolutely nothing even though .abort gets called and does not return any error.

Curious to know if you managed to solve it in a slightly different way

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

No branches or pull requests

5 participants