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

Fixes #750 - Throw error with stack trace when calling launch with an… #751

Closed

Conversation

austinkelleher
Copy link
Contributor

… invalid executablePath option.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. 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, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@austinkelleher
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

Copy link
Contributor

@aslushnikov aslushnikov left a comment

Choose a reason for hiding this comment

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

Good CL, thank you!

lib/Launcher.js Outdated
@@ -173,4 +176,14 @@ function waitForWSEndpoint(chromeProcess, timeout) {
});
}

function validateExecutablePath(chromeExecutable) {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's add jsdoc:

/**
 * @param {string} chromeExecutable
 * @return {!Promise}
 */

test/test.js Outdated
@@ -106,6 +106,12 @@ describe('Browser', function() {
await neverResolves;
expect(error.message).toContain('Protocol error');
}));
it('should reject if executable path is invalid', SX(async function() {
let waitError = null;
const launchOptions = Object.assign({ defaultBrowserOptions }, { executablePath: 'random-invalid-path' });
Copy link
Contributor

Choose a reason for hiding this comment

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

you want to extend default options with executable path:

const launchOptions = Object.assign({ executablePath: 'random-invalid-path' }, defaultBrowserOptions);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made a small change, but I don't think we should have { executablePath: ... } as the first argument to Object.assign(...) because if process.env.CHROME is supplied, then the executablePath supplied in Object.assign(...) will be overridden causing this test to fail.

const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});

https://github.com/GoogleChrome/puppeteer/pull/751/files#diff-c1129c8b045390789fa8ff62f2c6b4a9R111

@austinkelleher
Copy link
Contributor Author

@aslushnikov Thanks for the feedback. I made the changes and squashed.

@JoelEinbinder
Copy link
Collaborator

The executablePath actually takes a command right now. So you can set executablePath to "chrome-unstable" and it will fail this check but run correctly. Instead I think we should check for an error on childProcess.spawn.

@austinkelleher
Copy link
Contributor Author

@JoelEinbinder You're right. I will make the changes soon. Thanks.

@austinkelleher
Copy link
Contributor Author

Hey, so I was looking at attaching an error event listener to the spawned process (here: https://github.com/GoogleChrome/puppeteer/blob/master/lib/Launcher.js#L81), but I can't really think of a good way to reject with an error back to the puppeteer.launch(...) caller without introducing a timeout. Something like this (untested):

static async launch(options) {
  ...
  const chromeProcess = childProcess.spawn(chromeExecutable, chromeArguments, {detached: true});

  await new Promise((resolve, reject) => {
    let timeout = setTimeout(resolve, 1000);
    chromeProcess.on('error', () => {
      clearTimeout(timeout);
      reject(new Error(`Error launching Chromium process with executable path "${chromeExecutable}"`));
    });
  });
  ...
}

I don't really like the idea of introducing a timer, but I'm not sure what the best way of getting around it is.

We could simply just console.error inside of the chromeProcess.on('error') handler, but I'm not a huge fan of that either.

Thoughts @aslushnikov @JoelEinbinder?

@JoelEinbinder
Copy link
Collaborator

You can race chromeProcess.on('error') against waitForWSEndpoint. If the process sends us a valid websocket endpoint, I think we can safely assume Chrome launched successfully.

@austinkelleher
Copy link
Contributor Author

Thanks @JoelEinbinder. Sounds good. I will have the fix up soon.

@aslushnikov
Copy link
Contributor

@austinkelleher any updates on this?

@austinkelleher
Copy link
Contributor Author

Hey, @aslushnikov. I apologize for the delay on PR feedback. Got caught up in some other things. Should be able to get to this later today.

@aslushnikov
Copy link
Contributor

@austinkelleher thanks and no rush, I was mostly curious if you still have interest in this PR.

@austinkelleher
Copy link
Contributor Author

Whoops I need to make a few more changes. Hold on.

…h with an invalid executablePath option.
@austinkelleher
Copy link
Contributor Author

@aslushnikov @JoelEinbinder Thanks again for the feedback. I've addressed them all.

@austinkelleher
Copy link
Contributor Author

@aslushnikov @JoelEinbinder Can you please review my changes? Thanks!

@aslushnikov
Copy link
Contributor

@austinkelleher I apologize for the long reply, I'm currently traveling.

Codewise, I think this solution is a little too involved. It should be enough to catch the 'error' event on the chrome process - check out the #863.

@aslushnikov
Copy link
Contributor

Closing in favor of #863

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

Successfully merging this pull request may close these issues.

None yet

4 participants