Skip to content

Commit

Permalink
3.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ultrafunkamsterdam committed Nov 16, 2021
1 parent 77a3c30 commit ec49c00
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ Automatically downloads the driver binary and patches it.

- todo: work towards asyncification and selenium 4

#### words of wisdom: ####
Whenever you encounter the daunted

```from session not created: This version of ChromeDriver only supports Chrome version 96 # or what ever version```

the solution is simple:
```python
import undetected_chromedriver.v2 as uc
driver = uc.Chrome(version_main=95)
```



**July 2021: Currently busy implementing selenium 4 for undetected-chromedriver**

Expand All @@ -44,8 +56,7 @@ This is also the snippet i recommend using in case you experience an issue.
```python
import undetected_chromedriver.v2 as uc
driver = uc.Chrome()
with driver:
driver.get('https://nowsecure.nl') # known url using cloudflare's "under attack mode"
driver.get('https://nowsecure.nl') # known url using cloudflare's "under attack mode"
```

### The Version 2 more advanced way, including setting profie folder ###
Expand All @@ -66,10 +77,9 @@ options.add_argument('--user-data-dir=c:\\temp\\profile2')

# just some options passing in to skip annoying popups
options.add_argument('--no-first-run --no-service-autorun --password-store=basic')
driver = uc.Chrome(options=options)
driver = uc.Chrome(options=options, version_main=94) # version_main allows to specify your chrome version instead of following chrome global version

with driver:
driver.get('https://nowsecure.nl') # known url using cloudflare's "under attack mode"
driver.get('https://nowsecure.nl') # known url using cloudflare's "under attack mode"

```

Expand All @@ -86,7 +96,7 @@ However i implemented my own for now. Since i needed it myself for investigation
import undetected_chromedriver.v2 as uc
from pprint import pformat

driver = uc.Chrome(enable_cdp_event=True)
driver = uc.Chrome(enable_cdp_events=True)

def mylousyprintfunction(eventdata):
print(pformat(eventdata))
Expand All @@ -112,8 +122,7 @@ driver.add_cdp_listener('Network.dataReceived', mylousyprintfunction)

# now all these events will be printed in my console

with driver:
driver.get('https://nowsecure.nl')
driver.get('https://nowsecure.nl')


{'method': 'Network.requestWillBeSent',
Expand Down
2 changes: 1 addition & 1 deletion undetected_chromedriver/dprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _cleanup():
logging.getLogger(__name__).debug('cleaning up pid %d ' % pid)
os.kill(pid, signal.SIGTERM)
except: # noqa
traceback.print_exc()
pass


atexit.register(_cleanup)
Expand Down
10 changes: 10 additions & 0 deletions undetected_chromedriver/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys
import tempfile
import time
import inspect

import requests
import selenium.webdriver.chrome.service
Expand Down Expand Up @@ -646,6 +647,15 @@ def __del__(self):
self.quit()

def __enter__(self):
try:
curframe = inspect.currentframe()
callframe = inspect.getouterframes(curframe, 2)
caller = callframe[1][3]
logging.getLogger(__name__).debug('__enter__ caller: %s' % caller)
if caller == 'get':
return
except (AttributeError, ValueError, KeyError, OSError) as e:
logging.getLogger(__name__).debug(e)
return self

def __exit__(self, exc_type, exc_val, exc_tb):
Expand Down

0 comments on commit ec49c00

Please sign in to comment.