{"id":3447,"date":"2025-01-16T18:48:43","date_gmt":"2025-01-16T18:48:43","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2025\/01\/16\/launch-non-incognito-browser-windows-using-playwright-java\/"},"modified":"2025-01-16T18:48:43","modified_gmt":"2025-01-16T18:48:43","slug":"launch-non-incognito-browser-windows-using-playwright-java","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2025\/01\/16\/launch-non-incognito-browser-windows-using-playwright-java\/","title":{"rendered":"Launch Non-Incognito Browser Windows using Playwright Java"},"content":{"rendered":"<p><html><body><\/p>\n<section class=\"tcb-post-content tcb-shortcode thrv_wrapper\" data-css=\"tve-u-16ec5d248bb\">\n<div class=\"tve_flt tcb-style-wrap\" id=\"tve_flt\">\n<div class=\"tve_shortcode_editor tar-main-content\" data-post-id=\"3447\" id=\"tve_editor\">\n<div class=\"thrv_wrapper thrv_text_element\">\n<p><em>In this blog we will be utilizing Playwright Java to launch non-incognito browser windows.<\/em><\/p>\n<div class=\"code-block code-block-2\" style=\"margin: 8px auto; text-align: center; display: block; clear: both;\">\n<p><!-- horizontal responsive 2 --><br \/>\n<ins class=\"adsbygoogle\" data-ad-client=\"ca-pub-3231318496783163\" data-ad-format=\"auto\" data-ad-slot=\"2788468763\" data-full-width-responsive=\"true\" style=\"display:block\"><\/ins>\n<\/div>\n<p><strong>Topics that we will cover:<\/strong><\/p>\n<ul>\n<li>Launch browser in incognito (<em>private<\/em>) mode<\/li>\n<li>Launch Non-Incognito (<em>normal<\/em>) <em>Chromium<\/em> Browser<\/li>\n<li>Launch Non-Incognito <em>Chrome<\/em> Browser<\/li>\n<li>Launch Non-Incognito Chrome Browser <em>Default<\/em><br \/>\n<em>Profile<\/em><\/li>\n<li>Source code (incognito mode)<\/li>\n<li>Source code (Non-Incognito Chromium Browser)<\/li>\n<li>Source code (Non-Incognito Chrome Browser)<\/li>\n<li>Source code (Non-Incognito Chrome Browser Default Profile)<\/li>\n<\/ul>\n<p><strong>Launch browser in incognito (<\/strong><strong><em>private<\/em><\/strong><strong>) mode<\/strong><\/p>\n<p>So far we have been launching a browser in an incognito (private browser) mode.\u00a0<\/p>\n<p>This is the normal code that we have been running so far<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-19470755dd8\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3450\" data-css=\"tve-u-1947075708f\" data-height=\"243\" data-id=\"3450\" data-init-height=\"432\" data-init-width=\"1198\" data-width=\"674\" decoding=\"async\" height=\"243\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.20.19\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 432;\" title=\"Screenshot 2025-01-17 at 12.20.19\u202fAM\" width=\"674\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Let us run this code to launch the private chromium browser. You can see &#8216;incognito&#8217; mode in top right hand corner<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1947075f2f0\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3451\" data-css=\"tve-u-19470760412\" data-height=\"383\" data-id=\"3451\" data-init-height=\"672\" data-init-width=\"1198\" data-width=\"683\" decoding=\"async\" height=\"383\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.20.57\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 672;\" title=\"Screenshot 2025-01-17 at 12.20.57\u202fAM\" width=\"683\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0<strong>Launch Non-Incognito (<\/strong><strong><em>normal<\/em><\/strong><strong>) \u201cChromium\u201d Browser<\/strong><\/p>\n<p>At times we do NOT want to run a test in a private (incognito) browser. Instead we want to run the test in a &#8220;normal (non-incognito)&#8221; browser.\u00a0<\/p>\n<p>Let us see how to launch a chromium browser in a non-incognito window.<\/p>\n<p>In order to launch a normal (non-incognito) browser, first of all what we need to do is, instead of &#8220;launch&#8221;, we have to use &#8220;launchPersistentContext&#8221; method. This method accepts 2 parameters : one is the path viz the browser profile that you need to give. If we don\u2019t want to give path, we can keep it as blank as well: \u00a0\u00a0<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194707699c1\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3452\" data-css=\"tve-u-1947076a529\" data-height=\"663\" data-id=\"3452\" data-init-height=\"1282\" data-init-width=\"1198\" data-width=\"620\" decoding=\"async\" height=\"663\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.21.39\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 1282;\" title=\"Screenshot 2025-01-17 at 12.21.39\u202fAM\" width=\"620\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Execute and note that a non-incognito window has been launched, it is not a private browser<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-19470774920\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3453\" data-css=\"tve-u-194707753e8\" data-height=\"371\" data-id=\"3453\" data-init-height=\"654\" data-init-width=\"1198\" data-width=\"679\" decoding=\"async\" height=\"371\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.22.25\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 654;\" title=\"Screenshot 2025-01-17 at 12.22.25\u202fAM\" width=\"679\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0<strong>Launch Non-Incognito \u201cChrome\u201d Browser<\/strong><\/p>\n<p>Same thing we can do with chrome browser as well. We just need to setup the executable file path.<\/p>\n<p>We can say <em>.setExecutablePath(Paths.get(&#8220;&#8221;))<\/em> and give path of chrome exe: &#8220;C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe&#8221;\u00a0<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194707817cc\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3454\" data-css=\"tve-u-19470782bc4\" data-height=\"830\" data-id=\"3454\" data-init-height=\"1446\" data-init-width=\"1198\" data-width=\"688\" decoding=\"async\" height=\"830\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.23.03\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 1446;\" title=\"Screenshot 2025-01-17 at 12.23.03\u202fAM\" width=\"688\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0<strong>Launch Non-Incognito Chrome Browser Default Profile<\/strong><\/p>\n<p>In case you want to launch default chrome profile, than you can give the chrome profile path over here<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1947078e40f\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3455 tcb-moved-image\" data-css=\"tve-u-1947078efec\" data-height=\"683\" data-id=\"3455\" data-init-height=\"1180\" data-init-width=\"1198\" data-width=\"693\" decoding=\"async\" height=\"683\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.24.03\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 1180;\" title=\"Screenshot 2025-01-17 at 12.24.03\u202fAM\" width=\"693\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Execute<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-19470797a0e\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3456\" data-css=\"tve-u-19470798edd\" data-height=\"387\" data-id=\"3456\" data-init-height=\"686\" data-init-width=\"1198\" data-width=\"675\" decoding=\"async\" height=\"387\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.24.48\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 686;\" title=\"Screenshot 2025-01-17 at 12.24.48\u202fAM\" width=\"675\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>As seen above, we now see the entire history as well. So this is not the new profile. This is the same profile that you are running it by default.<\/p>\n<p>So this is how you can play around with profiles, you can launch multiple browser types (chrome, chromium etc) in non-incognito window using playwright.<\/p>\n<div class=\"tcb-plain-text\"><strong>Source code (incognito mode)<br \/><\/strong><strong>package<\/strong> com.rsa.playwrightjava;<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Browser;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.BrowserType;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Page;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Playwright;<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\"><strong>public<\/strong><br \/>\n<strong>class<\/strong> Blog25_Incognito {<\/div>\n<div class=\"tcb-plain-text\"><strong>public<\/strong><br \/>\n<strong>static<\/strong><br \/>\n<strong>void<\/strong> main(String[] args) {<\/div>\n<div class=\"tcb-plain-text\">Playwright playwright = Playwright.<em>create<\/em>();\u00a0<\/div>\n<div class=\"tcb-plain-text\">Browser browser = playwright.chromium().launch(<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>));<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\">Page page = browser.newPage();\u00a0<\/div>\n<div class=\"tcb-plain-text\">page.navigate(&#8220;https:\/\/rahulshettyacademy.com\/&#8221;);<\/div>\n<div class=\"tcb-plain-text\">page.pause();<\/div>\n<div class=\"tcb-plain-text\">}<\/div>\n<div class=\"tcb-plain-text\">}<\/div>\n<div class=\"tcb-plain-text\"><strong><br \/>Source code (Non-Incognito Chromium Browser)<br \/><\/strong><strong>package<\/strong> com.rsa.playwrightjava;<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> java.nio.file.Paths;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Browser;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.BrowserContext;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.BrowserType;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Page;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Playwright;<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\"><strong>public<\/strong><br \/>\n<strong>class<\/strong> Blog25_NonIncognitoChromiumBrowser {<\/div>\n<div class=\"tcb-plain-text\"><strong>public<\/strong><br \/>\n<strong>static<\/strong><br \/>\n<strong>void<\/strong> main(String[] args) {<\/div>\n<div class=\"tcb-plain-text\">Playwright playwright = Playwright.<em>create<\/em>();\u00a0<\/div>\n<div class=\"tcb-plain-text\">Browser browser = playwright.chromium().launch(<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>));<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\">BrowserContext browserContext= playwright.chromium().launchPersistentContext(Paths.<em>get<\/em>(&#8220;&#8221;), <strong>new<\/strong> BrowserType.LaunchPersistentContextOptions().setHeadless(<strong>false<\/strong>));<\/div>\n<div class=\"tcb-plain-text\">Page page = browserContext.newPage();<\/div>\n<div class=\"tcb-plain-text\">\/\/Page page = browser.newPage();<\/div>\n<div class=\"tcb-plain-text\">page.navigate(&#8220;https:\/\/courses.rahulshettyacademy.com\/courses\/&#8221;);<\/div>\n<div class=\"tcb-plain-text\">page.pause();<\/div>\n<div class=\"tcb-plain-text\">}<\/div>\n<div class=\"tcb-plain-text\">}<\/div>\n<div class=\"tcb-plain-text\"><strong><br \/>Source code (Non-Incognito Chrome Browser)<br \/><\/strong><strong>package<\/strong> com.rsa.playwrightjava;<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> java.nio.file.Paths;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Browser;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.BrowserContext;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.BrowserType;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Page;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Playwright;<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\"><strong>public<\/strong><br \/>\n<strong>class<\/strong> Blog25_NonIncognitoChromeBrowser {<\/div>\n<div class=\"tcb-plain-text\"><strong>public<\/strong><br \/>\n<strong>static<\/strong><br \/>\n<strong>void<\/strong> main(String[] args) {<\/div>\n<div class=\"tcb-plain-text\">Playwright playwright = Playwright.<em>create<\/em>();\u00a0<\/div>\n<div class=\"tcb-plain-text\">Browser browser = playwright.chromium().launch(<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>));<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\">BrowserContext browserContext= playwright.chromium().launchPersistentContext(Paths.<em>get<\/em>(&#8220;&#8221;), <strong>new<\/strong> BrowserType.LaunchPersistentContextOptions().setHeadless(<strong>false<\/strong>).setExecutablePath(Paths.<em>get<\/em>(&#8220;C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe&#8221;)));<\/div>\n<div class=\"tcb-plain-text\">Page page = browserContext.newPage();<\/div>\n<div class=\"tcb-plain-text\">\/\/Page page = browser.newPage();<\/div>\n<div class=\"tcb-plain-text\">page.navigate(&#8220;https:\/\/rahulshettyacademy.com\/lifetime-access&#8221;);<\/div>\n<div class=\"tcb-plain-text\">page.pause();<\/div>\n<div class=\"tcb-plain-text\">}<\/div>\n<div class=\"tcb-plain-text\">}<\/div>\n<div class=\"tcb-plain-text\"><strong><br \/>Source code (Non-Incognito Chrome Browser Default Profile)<\/strong><\/div>\n<div class=\"tcb-plain-text\"><strong>package<\/strong> com.rsa.playwrightjava;<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> java.nio.file.Paths;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Browser;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.BrowserContext;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.BrowserType;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Page;<\/div>\n<div class=\"tcb-plain-text\"><strong>import<\/strong> com.microsoft.playwright.Playwright;<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\"><strong>public<\/strong><br \/>\n<strong>class<\/strong> Blog25_NonIncognitoChromeBrowserDefaultProfile {<\/div>\n<div class=\"tcb-plain-text\"><strong>public<\/strong><br \/>\n<strong>static<\/strong><br \/>\n<strong>void<\/strong> main(String[] args) {<\/div>\n<div class=\"tcb-plain-text\">Playwright playwright = Playwright.<em>create<\/em>();\u00a0<\/div>\n<div class=\"tcb-plain-text\">Browser browser = playwright.chromium().launch(<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>));<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\">BrowserContext browserContext= playwright.chromium().launchPersistentContext(Paths.<em>get<\/em>(&#8220;C:\\Users\\DELL\\AppData\\Local\\Google\\Chrome\\User Data\\Default&#8221;), <strong>new<\/strong> BrowserType.LaunchPersistentContextOptions().setHeadless(<strong>false<\/strong>).setExecutablePath(Paths.<em>get<\/em>(&#8220;C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe&#8221;)));<\/div>\n<div class=\"tcb-plain-text\">Page page = browserContext.newPage();<\/div>\n<div class=\"tcb-plain-text\">\/\/Page page = browser.newPage();<\/div>\n<div class=\"tcb-plain-text\">page.navigate(&#8220;https:\/\/rahulshettyacademy.com\/lifetime-access&#8221;);<\/div>\n<div class=\"tcb-plain-text\">page.pause();<\/div>\n<div class=\"tcb-plain-text\">}<\/div>\n<div class=\"tcb-plain-text\">}<\/div>\n<div class=\"tcb-plain-text\"><\/div>\n<div class=\"tcb-plain-text\">Thanks.<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"tcb_flag\" style=\"display: none\"><\/div>\n<\/section>\n<p><\/body><\/html><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog we will be utilizing Playwright Java to launch non-incognito browser windows. Topics that we will cover: Launch browser in incognito (private) mode Launch Non-Incognito (normal) Chromium Browser Launch Non-Incognito Chrome Browser Launch Non-Incognito Chrome Browser Default Profile Source code (incognito mode) Source code (Non-Incognito Chromium Browser) Source code (Non-Incognito Chrome Browser) Source [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,9],"tags":[],"class_list":["post-3447","post","type-post","status-publish","format-standard","hentry","category-java","category-playwright","post-wrapper","thrv_wrapper"],"_links":{"self":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=3447"}],"version-history":[{"count":0,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3447\/revisions"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=3447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=3447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=3447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}