File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ """Using CDP.fetch.RequestPaused to modify requests in real-time."""
2
+ import mycdp
3
+ from seleniumbase import SB
4
+
5
+
6
+ async def request_paused_handler (event , tab ):
7
+ r = event .request
8
+ is_image = ".png" in r .url or ".jpg" in r .url or ".gif" in r .url
9
+ if not is_image : # Let the data through
10
+ tab .feed_cdp (mycdp .fetch .continue_request (request_id = event .request_id ))
11
+ else : # Modify the data (change the image)
12
+ tab .feed_cdp (mycdp .fetch .continue_request (
13
+ request_id = event .request_id ,
14
+ url = "https://seleniumbase.io/other/with_frakes.jpg"
15
+ ))
16
+
17
+
18
+ with SB (uc = True , test = True , locale_code = "en" , pls = "none" ) as sb :
19
+ sb .activate_cdp_mode ("about:blank" )
20
+ sb .cdp .add_handler (mycdp .fetch .RequestPaused , request_paused_handler )
21
+ sb .cdp .open ("https://gettyimages.com/photos/jonathan-frakes-cast-2022" )
22
+ new_size = "--width:100;--height:100;"
23
+ sb .cdp .set_attributes ('[style*="--width:"]' , "style" , new_size )
24
+ sb .sleep (6 )
You can’t perform that action at this time.
0 commit comments