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

feat: add channel parameter for puppeteer.launch #7389

Merged
merged 6 commits into from Jul 9, 2021
Merged

feat: add channel parameter for puppeteer.launch #7389

merged 6 commits into from Jul 9, 2021

Conversation

YusukeIwaki
Copy link
Contributor

Add 'channel' parameter for Puppeteer.launch

Resolves #7340

Google Chrome is often used for using puppeteer as a browser automation tool,
We have to specify executablePath in such case. However we can't share the code among Windows/macOS users, because executablePath is different.

microsoft/playwright already introduced the channel parameter for solving this problem.
Let's provide the similar functionality for Puppeteer users.

const puppeteer = require('puppeteer');

puppeteer.launch({ channel: 'chrome-canary', headless: false }).then(async (browser) => {
    const page = await browser.newPage();
    await page.goto('https://github.com/puppeteer');
    await browser.close();
});

@google-cla
Copy link

google-cla bot commented Jun 29, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Jun 29, 2021
@YusukeIwaki
Copy link
Contributor Author

@googlebot I signed it!

@google-cla google-cla bot added cla: yes and removed cla: no labels Jun 29, 2021
@YusukeIwaki YusukeIwaki changed the title feat: add channel parameter feat: add channel parameter for puppeteer.launch Jun 29, 2021
@YusukeIwaki YusukeIwaki marked this pull request as ready for review June 29, 2021 22:17
Copy link
Contributor

@jschfflr jschfflr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good to me, thanks for your contribution!
I left some comments and maybe we should also think about whether PUPPETEER_EXECUTABLE_PATH should take precedence over the channel or not.
Let me know what you think!

test/launcher.spec.ts Outdated Show resolved Hide resolved
src/node/Launcher.ts Show resolved Hide resolved
@YusukeIwaki
Copy link
Contributor Author

YusukeIwaki commented Jul 1, 2021

Thank you for your kind review. I considered again about the priority of channel and executablePath.

  • [1] executablePath should be ignored when channel is specified
  • [2] executablePath should be respected even when channel is specified

[1] is actually adopted in Playwright. This is really simple. I think [1] is better.

The use-case of [2] is like below:
When some users changed the install path of Chrome, channel: chrome fails to detect Chrome. Without modifying the script source code, users can set the install path with PUPPETEER_EXECUTABLE_PATH=/path/to/chrome

However in [2], users can also specify MS Edge as executablePath even when channel: chrome.
If the script developer intends to the script is assumed to work with Chrome, PUPPETEER_EXECUTABLE_PATH=/path/to/msedge is just a source of worry.

This is just my observation but I didn't see the people who change the Chrome install path, and I thought [2] is useful for only a few people. IMO, simplicity is better than considering the edge case.
So I suggedt the spec [1] executablePath should be ignored when channel is specified

Copy link
Contributor

@jschfflr jschfflr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me from a technical point of view now.
But please also update the documentation in docs/api.md to explain the change.

src/node/Launcher.ts Outdated Show resolved Hide resolved
@jschfflr
Copy link
Contributor

jschfflr commented Jul 4, 2021

Regarding the priority: Let's make them mutually exclusive.
If one of them is specified, the other one can not be set - that way, people don't run into unexpected behaviour.
Can you add an assert for that?

@YusukeIwaki
Copy link
Contributor Author

Regarding the priority: Let's make them mutually exclusive.
If one of them is specified, the other one can not be set - that way, people don't run into unexpected behaviour.

That's a good idea. I will add assertion for it.

@google-cla
Copy link

google-cla bot commented Jul 4, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes labels Jul 4, 2021
docs/api.md Outdated Show resolved Hide resolved
src/node/Launcher.ts Show resolved Hide resolved
@google-cla
Copy link

google-cla bot commented Jul 5, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Jul 5, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@YusukeIwaki
Copy link
Contributor Author

YusukeIwaki commented Jul 6, 2021

@jschfflr Thank you for your kind review.
Could you re-run GitHub actions? The failed test is caused by flaky testcase.

@jschfflr
Copy link
Contributor

jschfflr commented Jul 6, 2021

Sure :)

@google-cla
Copy link

google-cla bot commented Jul 6, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: yes and removed cla: no labels Jul 8, 2021
@YusukeIwaki
Copy link
Contributor Author

Rebased.

Copy link
Contributor

@jschfflr jschfflr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change LGTM now!

@jschfflr jschfflr enabled auto-merge (squash) July 9, 2021 12:31
@jschfflr jschfflr merged commit d70f60e into puppeteer:main Jul 9, 2021
@jschfflr
Copy link
Contributor

jschfflr commented Jul 9, 2021

Your change landed 🎉
Thanks for your contribution @YusukeIwaki!

@YusukeIwaki YusukeIwaki deleted the feature/launch_with_channel branch July 9, 2021 13:15
jschfflr pushed a commit that referenced this pull request Sep 10, 2021
This change adds a new `channel` parameter to `puppeteer.launch`. When specified, Puppeteer will search for the locally installed release channel of Google Chrome and use it to launch. Available values are `chrome`, `chrome-beta`, `chrome-canary`, `chrome-dev`. This parameter is mutually exclusive with `executablePath`.
@noinkling
Copy link

noinkling commented Jan 10, 2022

Any particular reason this feature only checks Program Files and not also Program Files (x86) on Windows? My Chrome installation is located in the latter. According to this it was the default location until 2020. For installations existing before that point, it seems like the only (non-hacky) way to move it is to uninstall and reinstall.

Playwright appears to look in both (as well as in AppData/Local, which I seem to remember was indeed where the executable lived at one point), if that's any motivation: https://github.com/microsoft/playwright/blob/b6eb917c29b743e8d63004ae7a24974404461198/packages/playwright-core/src/utils/registry.ts#L461

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

Successfully merging this pull request may close these issues.

Feature Request: 'channel' parameter like Playwright
3 participants