Skip to content

Commit 5984207

Browse files
committed
Add an example of changing the timezone with CDP
1 parent 64943b2 commit 5984207

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

examples/cdp_mode/raw_timezone.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Timezone example using CDP Mode without WebDriver"""
2+
import mycdp
3+
from seleniumbase import decorators
4+
from seleniumbase import sb_cdp
5+
6+
7+
async def request_paused_handler(event, tab):
8+
r = event.request
9+
is_image = ".png" in r.url or ".jpg" in r.url or ".gif" in r.url
10+
if not is_image: # Let the data through
11+
tab.feed_cdp(mycdp.fetch.continue_request(request_id=event.request_id))
12+
else: # Block the data (images)
13+
TIMED_OUT = mycdp.network.ErrorReason.TIMED_OUT
14+
tab.feed_cdp(mycdp.fetch.fail_request(event.request_id, TIMED_OUT))
15+
16+
17+
@decorators.print_runtime("Timezone CDP Example")
18+
def main():
19+
url = "https://www.randymajors.org/what-time-zone-am-i-in"
20+
sb = sb_cdp.Chrome(
21+
url,
22+
ad_block=True,
23+
lang="bn",
24+
tzone="Asia/Kolkata",
25+
geoloc=(26.855323, 80.937710)
26+
)
27+
sb.add_handler(mycdp.fetch.RequestPaused, request_paused_handler)
28+
sb.remove_elements("#right-sidebar")
29+
sb.remove_elements('[id*="Footer"]')
30+
sb.sleep(6)
31+
32+
33+
if __name__ == "__main__":
34+
main()

0 commit comments

Comments
 (0)