Estou usando o SeleniumBase no modo CDP.
Estou tentando descobrir como definir o tamanho da janela no Modo CDP DEPOIS que o site for carregado?
Se eu usar a função não CDP sb.set_window_size(x,y)
, ele será detectado como bot runtimeEnableLeak
para abrir devtools em https://bot-detector.rebrowser.net :
Eu tentei sb.cdp.set_window_size(x,y)
, mas essa função parece não existir, pois trava com:
sb.cdp.set_window_size(x,y)
AttributeError: 'types.SimpleNamespace' object has no attribute 'set_window_size'
EDIT: Consegui encontrar uma solução alternativa usando sb.cdp.set_window_rect
:
[screenwidth,screenheight,innerwidth,innerheight,scrollwidth,scrollheight] = sb.cdp.evaluate("return [window.screen.width, window.screen.height, window.innerWidth, window.innerHeight, document.documentElement.scrollWidth, document.documentElement.scrollHeight];")
print(f"Size: {screenwidth}, {screenheight}, {innerwidth}, {innerheight}, {scrollwidth}, {scrollheight}")
sb.cdp.set_window_rect(0,0,scrollwidth + screenwidth - innerwidth, scrollheight + screenheight - innerheight + 100)
print(f"Sleeping for some time...")
sb.sleep(random.randint(5, 8))
Existe uma maneira melhor?
Use
sb.cdp.set_window_rect(x, y, width, height)
. (Todos os 4 parâmetros precisam ser definidos.) Por exemplo: