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: https://httpbin.org/get):
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('https://httpbin.org/relative-redirect/1', { waitUntil: 'load' });
const redirectPage = context.pages()[context.pages().length - 1];
console.log(redirectPage.evaluate(() => {
return document.location.toString();
}));
page.close();
browser.close();
}
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 However, you could help us implement these features if you could provide us a website and your script. So we can plan for it.
Thanks!