Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Tell the browser playwright is running it #19584

Closed
goldylucks opened this issue Dec 20, 2022 · 4 comments
Closed

[Feature] Tell the browser playwright is running it #19584

goldylucks opened this issue Dec 20, 2022 · 4 comments

Comments

@goldylucks
Copy link

I want my app to know it's running under playwright, one use case is running tests on production environment, and telling the html to NOT load google analytics and other trackers.

How can I go about it?

@vovsemenv
Copy link
Contributor

vovsemenv commented Dec 20, 2022

pw have bunch of globally injected variables like __pw_recorderState.
see more

you can use it 🙌🏽

@pavelfeldman
Copy link
Member

The answer above is not correct, recorder is not there when codegen is not recording. You can do something like this:

test.beforeEach(({ context }) => {
  await context.addInitScript(() => window.isUnderTest = true);
});

then in your page, you can do

if (window.isUnderTest) ...

@pavelfeldman
Copy link
Member

Closing as per above, please feel free to open a new issue if this does not cover your use case.

@tsvetkovv
Copy link

For everyone else who come to solve the same issue, use navigate.webdriver property. You don't need to set anything from playwright

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants