question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

wss:// requests forcing interceptor of selenium-wire into a infinite loop

See original GitHub issue

I am trying to Intercept a specific request on a website. Once you’ve created a account on it and are browsing with that account; the website seems to launch a wss request (most likely for the onsite chat feature). This wss request is putting selenium-wire into a infinite loop, either constantly triggering it or triggering the couple requests that would come before or after it (but all those requests erroring out). This in return never allows the website to launch all requests in a normally successful order. To be honest, I am not too sure if it’s the wss request alone or the seemingly failing ssl certificate verification. I already tried doing verify=False in selenium-wire options that didn’t change anything. Loading the website without my own user data dir / without a account on the website, the wss request seems to pass through, most likely because you can’t connect with the websocket request if you are not authenticated (have a user account on the website).

Here’s a visual representation of said issue: https://youtu.be/glnykmuG-cw

Please help me out 🙏 @wkeeling

import seleniumwire.undetected_chromedriver as uc
import re, os

chrome_options = uc.ChromeOptions()

# after creating a account on the website I am copying local data from browser here;
# so that I can browse the website with a authenticated selenium session
for e in ['--disable-extensions', fr'--user-data-dir={os.getenv("localappdata")}\Google\Chrome\User Data']:
    chrome_options.add_argument(e)
chrome_options.headless = False

driver = uc.Chrome(options=chrome_options, use_subprocess=True)

def interceptor(request):
    print(request.url)

driver.request_interceptor = interceptor
driver.get('https://fansly.com/')
input()

Selenium-wire version 4.6.3 | UC version 3.1.5.post4 | Python version 3.10.4 | Windows 10

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wkeelingcommented, May 11, 2022

@randolfvalerija

I was hoping to use the request interceptor to catch the ws messages on the fly.

Yes this isn’t currently possible for websocket messages. You’ll need to wait for the request/response to fully complete, then access the messages via the ws_messages attribute.

0reactions
wkeelingcommented, May 20, 2022

@Avnsx sorry for the delay coming back on this. I’ve tried reproducing by creating a fansly.com account, signing in manually and then pointing Selenium Wire/undetected chromedriver at the user data folder. Chrome opens fansly.com up straight into the logged in session as expected. Checking the network panel and all looks well - there seems to be no errors relating to any requests as far as I can see. I tried clicking around and it seems OK.

The only difference is that I’m running on Linux and it looks as though you’re using Windows. The user data folder on Linux lives in ~/.config/google-chrome/

My code is pretty much the same as yours:

chrome_options = uc.ChromeOptions()
for e in [
    '--disable-extensions',
    '--user-data-dir=/tmp/google-chrome',  # Contains the logged in session
    '--profile-directory=Profile_1'
]:
    chrome_options.add_argument(e)

driver = uc.Chrome(options=chrome_options, use_subprocess=True)
driver.get('https://fansly.com/')
input()

driver.quit()
Read more comments on GitHub >

github_iconTop Results From Across the Web

selenium-wire - PyPI
An interceptor is a function that gets invoked with requests and responses as they pass through Selenium Wire. Within an interceptor you can...
Read more >
Interceptors not working after attaching to existing browser ...
We have some tests written in Pylenium, and we will like to use selenium-wire to mock some requests/responses. The tests follow some path ......
Read more >
Infinite loop in interceptor - angularjs - Stack Overflow
So this code: Starts when the first request fails; Refreshes the token; Retries the request but fails again (<- I just want to...
Read more >
Python Selenium Tutorial #8 - Capture, Block & Mock ...
Selenium Wire extends Selenium's Python bindings to give you access ... In this video, I show how we can " Intercept " requests...
Read more >
Web Scraping with Selenium in Python - ZenRows
Learn how to navigate and scrape websites using Selenium in Python, ... It will allow us to intercept requests, among other things, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found