How to handle a redirected page

using Playwright Test and Puppeteer I am able to retrieve a redirected page using this syntax:

redirectPage = browser.contexts()[0].pages()[browser.contexts()[0].pages().length - 1];

this syntax does not work when using the custom built k6 executable that was built using the xk6 - Custom k6 Builder

the command to launch the redirected page is carried out and the redirected page appears but unfortunately that is the end of my user flow since the selector is never found

Hi @jmkrakowski,

Welcome to the community!

I tried the following, and it worked (it prints the redirected page’s URL:

import launcher from 'k6/x/browser';

export default function() {
  const browser = launcher.launch('chromium', { headless: false });
  const context = browser.newContext();
  const page = context.newPage();
  page.goto('', { waitUntil: 'load' });

  const redirectPage = context.pages()[context.pages().length - 1];
  console.log(redirectPage.evaluate(() => {
    return document.location.toString();

Let me know if it helps. Thanks!

Thanks for your response. I did forget to mention that this redirected page does launch in a new browser window.

using your sample showed this:

INFO[0002] before call pages: 2 source=console
INFO[0003] after call pages: 2 source=console

using playwright test shows this:
2.0-number of browser context pages before redirected page: 1
2.1-number of browser context pages after redirected page: 2

using xk6 with my sample the page number is the same just as yours BUT the url is also the same

elaborating even further - think of OAuth redirection using redirect_uri

Hey @jmkrakowski,

I’m afraid we don’t support new browser windows and OAuth yet :frowning: However, you could help us implement these features if you could provide us a website and your script. So we can plan for it.


1 Like

Hi @inancgumus

is this feature is aviable now? our application is enabled with Azure AD authentication.

Hi @hegde89,

No, it’s not yet available :frowning: Could you raise an issue on our repository? Anyone reading this, please do not forget to give the issue a thumbs up. So we can know how many of our users want this feature. We’ll prioritize it accordingly.


1 Like

Hi @inancgumus

We are in the early adoption stage of incorporating k6 Browser into our project.

Our project is an Angular application. Could you please help us determine if we can achieve the following scenario using k6 Browser Testing?

  1. Load the Home Page.
  2. Click on the logo image. This action will redirect the page to the Microsoft AzureAD SSO login page.
  3. Upon successful login, the page will be redirected back to the Home Page.
1 Like


As I mentioned, we don’t support OAuth yet. If it’s possible, it would be great if you give the browser module a try and let us know how it goes. This will let us explore what we’re missing.