{"id":3447,"date":"2025-01-16T18:48:43","date_gmt":"2025-01-16T18:48:43","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/?p=3447"},"modified":"2025-01-17T10:46:54","modified_gmt":"2025-01-17T10:46:54","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\u00a0"},"content":{"rendered":"<p><em>In this blog we will be utilizing Playwright Java to launch non-incognito browser windows.<\/em><\/p>\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><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.&nbsp;<\/p>\n<p>This is the normal code that we have been running so far<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3450\" width=\"674\" data-init-width=\"1198\" height=\"243\" data-init-height=\"432\" title=\"Screenshot 2025-01-17 at 12.20.19\u202fAM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.20.19\u202fAM.png\" data-width=\"674\" data-height=\"243\" style=\"aspect-ratio: auto 1198 \/ 432;\"><\/span><\/p>\n<p>&nbsp;Let us run this code to launch the private chromium browser. You can see &#8216;incognito&#8217; mode in top right hand corner<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3451\" width=\"683\" data-init-width=\"1198\" height=\"383\" data-init-height=\"672\" title=\"Screenshot 2025-01-17 at 12.20.57\u202fAM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.20.57\u202fAM.png\" data-width=\"683\" data-height=\"383\" style=\"aspect-ratio: auto 1198 \/ 672;\"><\/span><\/p>\n<p>&nbsp;<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.&nbsp;<\/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: &nbsp;&nbsp;<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3452\" width=\"620\" data-init-width=\"1198\" height=\"663\" data-init-height=\"1282\" title=\"Screenshot 2025-01-17 at 12.21.39\u202fAM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.21.39\u202fAM.png\" data-width=\"620\" data-height=\"663\" style=\"aspect-ratio: auto 1198 \/ 1282;\"><\/span><\/p>\n<p>Execute and note that a non-incognito window has been launched, it is not a private browser<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3453\" width=\"679\" data-init-width=\"1198\" height=\"371\" data-init-height=\"654\" title=\"Screenshot 2025-01-17 at 12.22.25\u202fAM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.22.25\u202fAM.png\" data-width=\"679\" data-height=\"371\" style=\"aspect-ratio: auto 1198 \/ 654;\"><\/span><\/p>\n<p>&nbsp;<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;&nbsp;<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3454\" width=\"688\" data-init-width=\"1198\" height=\"830\" data-init-height=\"1446\" title=\"Screenshot 2025-01-17 at 12.23.03\u202fAM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.23.03\u202fAM.png\" data-width=\"688\" data-height=\"830\" style=\"aspect-ratio: auto 1198 \/ 1446;\"><\/span><\/p>\n<p>&nbsp;<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<p><span><img decoding=\"async\" alt=\"\" data-id=\"3455\" width=\"693\" data-init-width=\"1198\" height=\"683\" data-init-height=\"1180\" title=\"Screenshot 2025-01-17 at 12.24.03\u202fAM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.24.03\u202fAM.png\" data-width=\"693\" data-height=\"683\" style=\"aspect-ratio: auto 1198 \/ 1180;\"><\/span><\/p>\n<p>Execute<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3456\" width=\"675\" data-init-width=\"1198\" height=\"387\" data-init-height=\"686\" title=\"Screenshot 2025-01-17 at 12.24.48\u202fAM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.24.48\u202fAM.png\" data-width=\"675\" data-height=\"387\" style=\"aspect-ratio: auto 1198 \/ 686;\"><\/span><\/p>\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<p><strong>Source code (incognito mode)<\/strong><strong>package<\/strong> com.rsa.playwrightjava;<strong>import<\/strong> com.microsoft.playwright.Browser;<strong>import<\/strong> com.microsoft.playwright.BrowserType;<strong>import<\/strong> com.microsoft.playwright.Page;<strong>import<\/strong> com.microsoft.playwright.Playwright;<strong>public<\/strong><strong>class<\/strong> Blog25_Incognito {<strong>public<\/strong><strong>static<\/strong><strong>void<\/strong> main(String[] args) {Playwright playwright = Playwright.<em>create<\/em>();&nbsp;Browser browser = playwright.chromium().launch(<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>));Page page = browser.newPage();&nbsp;page.navigate(&#8220;https:\/\/rahulshettyacademy.com\/&#8221;);page.pause();}}<strong>Source code (Non-Incognito Chromium Browser)<\/strong><strong>package<\/strong> com.rsa.playwrightjava;<strong>import<\/strong> java.nio.file.Paths;<strong>import<\/strong> com.microsoft.playwright.Browser;<strong>import<\/strong> com.microsoft.playwright.BrowserContext;<strong>import<\/strong> com.microsoft.playwright.BrowserType;<strong>import<\/strong> com.microsoft.playwright.Page;<strong>import<\/strong> com.microsoft.playwright.Playwright;<strong>public<\/strong><strong>class<\/strong> Blog25_NonIncognitoChromiumBrowser {<strong>public<\/strong><strong>static<\/strong><strong>void<\/strong> main(String[] args) {Playwright playwright = Playwright.<em>create<\/em>();&nbsp;Browser browser = playwright.chromium().launch(<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>));BrowserContext browserContext= playwright.chromium().launchPersistentContext(Paths.<em>get<\/em>(&#8220;&#8221;), <strong>new<\/strong> BrowserType.LaunchPersistentContextOptions().setHeadless(<strong>false<\/strong>));Page page = browserContext.newPage();\/\/Page page = browser.newPage();page.navigate(&#8220;https:\/\/courses.rahulshettyacademy.com\/courses\/&#8221;);page.pause();}}<strong>Source code (Non-Incognito Chrome Browser)<\/strong><strong>package<\/strong> com.rsa.playwrightjava;<strong>import<\/strong> java.nio.file.Paths;<strong>import<\/strong> com.microsoft.playwright.Browser;<strong>import<\/strong> com.microsoft.playwright.BrowserContext;<strong>import<\/strong> com.microsoft.playwright.BrowserType;<strong>import<\/strong> com.microsoft.playwright.Page;<strong>import<\/strong> com.microsoft.playwright.Playwright;<strong>public<\/strong><strong>class<\/strong> Blog25_NonIncognitoChromeBrowser {<strong>public<\/strong><strong>static<\/strong><strong>void<\/strong> main(String[] args) {Playwright playwright = Playwright.<em>create<\/em>();&nbsp;Browser browser = playwright.chromium().launch(<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>));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;)));Page page = browserContext.newPage();\/\/Page page = browser.newPage();page.navigate(&#8220;https:\/\/rahulshettyacademy.com\/lifetime-access&#8221;);page.pause();}}<strong>Source code (Non-Incognito Chrome Browser Default Profile)<\/strong><strong>package<\/strong> com.rsa.playwrightjava;<strong>import<\/strong> java.nio.file.Paths;<strong>import<\/strong> com.microsoft.playwright.Browser;<strong>import<\/strong> com.microsoft.playwright.BrowserContext;<strong>import<\/strong> com.microsoft.playwright.BrowserType;<strong>import<\/strong> com.microsoft.playwright.Page;<strong>import<\/strong> com.microsoft.playwright.Playwright;<strong>public<\/strong><strong>class<\/strong> Blog25_NonIncognitoChromeBrowserDefaultProfile {<strong>public<\/strong><strong>static<\/strong><strong>void<\/strong> main(String[] args) {Playwright playwright = Playwright.<em>create<\/em>();&nbsp;Browser browser = playwright.chromium().launch(<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>));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;)));Page page = browserContext.newPage();\/\/Page page = browser.newPage();page.navigate(&#8220;https:\/\/rahulshettyacademy.com\/lifetime-access&#8221;);page.pause();}}Thanks.<\/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 DefaultProfile Source code (incognito mode) Source code (Non-Incognito Chromium Browser) Source code (Non-Incognito Chrome Browser) Source code [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":750,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[],"class_list":["post-3447","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","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":6,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3447\/revisions"}],"predecessor-version":[{"id":3735,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3447\/revisions\/3735"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/750"}],"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}]}}