'Start playwright driver session but not incognito
Currently i open a new browser session using the code below, but it always starts as incognito, can I start a new chromium session but not as incognito?:
from behave import *
from playwright.sync_api import sync_playwright
import time
class session_driver:
driver = None
def open_browser(self, url):
playW_sync_instace = sync_playwright().start()
global browser
browser = playW_sync_instace.chromium.launch(headless=False)
browser.new_context(record_video_dir="videos/",
record_video_size={"width": 640, "height": 480})
self.driver = browser.new_page()
self.driver.goto(url)
Solution 1:[1]
from playwright.sync_api import sync_playwright
import os
user_dir = '/tmp/playwright'
if not os.path.exists(user_dir):
os.makedirs(user_dir)
with sync_playwright() as p:
browser = p.chromium.launch_persistent_context(user_dir, headless=False)
page = browser.new_page()
page.goto('https://playwright.dev/python', wait_until='domcontentloaded')
Solution 2:[2]
This is what I have done in Typescript code base. But this would leverage the existing logged-in session, and it would not ask for fresh user login.
const userDataDir = 'C:/Users/yuv****dir/AppData/Local/Temp/tjwmm3m0.hmt';
context = await chromium.launchPersistentContext(userDataDir,{ headless: false, args: [ ] });
I hope this is like above only what is there in Python code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kayce Basques |
Solution 2 | yuvraj |