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

generate .d.ts better than what's on definitelytyped #6

Closed
8 of 10 tasks
JoelEinbinder opened this issue Nov 19, 2019 · 16 comments
Closed
8 of 10 tasks

generate .d.ts better than what's on definitelytyped #6

JoelEinbinder opened this issue Nov 19, 2019 · 16 comments
Assignees

Comments

@JoelEinbinder
Copy link
Contributor

JoelEinbinder commented Nov 19, 2019

  • Types include descriptions from api.md
  • Private methods are excluded
  • Private intermediate types are excluded
  • Typed protocol for ChromiumSession
  • Don't lose type information from page.evaluate
  • Templated JSHandles
  • Always up to date with the API
  • Consider types part of the API, never break them
  • Enums for important string constants, e.g. LifecycleEvent and KeyboardKey.
  • Sort out waitFor's many call signatures
@JoelEinbinder JoelEinbinder self-assigned this Nov 19, 2019
This was referenced Dec 5, 2019
JoelEinbinder added a commit that referenced this issue Dec 6, 2019
This makes it so that JSHandles and ElementHandles are aware of what types they point to. As a fun bonus, `$eval('input')` knows its going to get an HTMLInputElement.

Most of this patch is casting things where previously we just assumed ElementHandles held the right kind of node. This gets us closer to being able to turn on `noImplicityAny` as well.

#6
JoelEinbinder added a commit that referenced this issue Dec 6, 2019
`protocol.d.ts` had to move to `protocol.ts` otherwise typescript refuses to include it in the out directory.

Removed the old d.ts generator. It will need to be rewritten anyway.

These new types include private stuff that they probably shouldn't, and are missing documentation. I'll follow up with a better d.ts generator later.

#6
@dgozman
Copy link
Contributor

dgozman commented Feb 28, 2020

I suggest to drop ChromiumSession from v1 altogether.

@mxschmitt
Copy link
Member

Is it also possible, that a single file will be created which contains all the typings in the end? Like Electron does. Or is this already included / done in your task list / PR?

cc @JoelEinbinder

Thanks!

@JoelEinbinder
Copy link
Contributor Author

Is it also possible, that a single file will be created which contains all the typings in the end? Like Electron does. Or is this already included / done in your task list / PR?

cc @JoelEinbinder

Thanks!

I didn’t have that as an explicit goal, but it will likely end up with one file for the core types, and one file per package like playwright, playwright-chromium, that reexports some of those types. Is there some reason that having a single file with all of the types is preferable?

@mxschmitt
Copy link
Member

Is it also possible, that a single file will be created which contains all the typings in the end? Like Electron does. Or is this already included / done in your task list / PR?
cc @JoelEinbinder
Thanks!

I didn’t have that as an explicit goal, but it will likely end up with one file for the core types, and one file per package like playwright, playwright-chromium, that reexports some of those types. Is there some reason that having a single file with all of the types is preferable?

I try to embed the typings into the Monaco editor to use them there and for that I need to load them "somehow" into the frontend. For Electron (just a random example) it works by simply using the single file, thats why I thought this is common.

JoelEinbinder added a commit that referenced this issue Mar 4, 2020
This adds a new check to doclint for whether a member is correctly marked as optional. 
part of #6
@thernstig
Copy link
Contributor

This snippet does not give proper types for el:

    await page.$eval('input[type=text]', el => {
      // @ts-ignore
      el.value = '';
    });

I'm using VS Code. Removing // @ts-ignore will give an error saying Property 'value' does not exist on type 'Element'.ts(2339). Is this part of this issue?

@JoelEinbinder
Copy link
Contributor Author

This snippet does not give proper types for el:

    await page.$eval('input[type=text]', el => {
      // @ts-ignore
      el.value = '';
    });

I'm using VS Code. Removing // @ts-ignore will give an error saying Property 'value' does not exist on type 'Element'.ts(2339). Is this part of this issue?

No this is standard behavior with typescript. Replace $eval with document.querySelector and the same thing will happen.

@thernstig
Copy link
Contributor

thernstig commented Mar 7, 2020

@JoelEinbinder or @aslushnikov Any recommended way to work around that, i.e. to achieve the same thing but with autocompletion for el? Basicallly what I want to do is reset an input field at the start of each test I run. Is the the only workaround to get auto-completion to do like below? Below el does give auto-completion, hence why I thought page.$eval would also give it after finding the element.

const foo= await page.waitForSelector('text="Something"');
expect(await foo.evaluate(el => el.innerText)).toBe('Something');

@JoelEinbinder
Copy link
Contributor Author

@JoelEinbinder or @aslushnikov Any recommended way to work around that, i.e. to achieve the same thing but with autocompletion for el? Basicallly what I want to do is reset an input field at the start of each test I run. Is the the only workaround to get auto-completion to do like below? Below el does give auto-completion, hence why I thought page.$eval would also give it after finding the element.

const foo= await page.waitForSelector('text="Something"');
expect(await foo.evaluate(el => el.innerText)).toBe('Something');

I believe waitForSelector had the wrong types. They should both behave the same after my pr lands.

@thernstig
Copy link
Contributor

@JoelEinbinder I will follow this up once your PR lands and report any existing issues I have, so we can sort it out what's incorrect and not. I find it so weird that this (see image) gives autocompletion for everything but .value.

autocompletion_value

JoelEinbinder added a commit that referenced this issue Mar 20, 2020
This generates typescript definitions based on the api.md, instead of autogenerating them from the typescript source code.

Now types
 - only include the public api
 - work with older versions of typescript
 - include descriptions
 - are more consistent
 - are more complete

#6
@thernstig
Copy link
Contributor

@JoelEinbinder Did you see my above image? There you can see that el.nodeValue gives auto-completion, but not el.value. Do you mean that el.value will never give auto-completion then? If so, how do I work around this in e.g. VS Code?

    await page.$eval('input[type=text]', el => {
      // @ts-ignore
      el.value = '';
    });

@dgozman
Copy link
Contributor

dgozman commented Apr 3, 2020

If I am not mistaken, manual typing should work in this case:

await page.$eval('input[type=text]', (el: HTMLInputElement) => {
  el.value = '';
});

@mxschmitt
Copy link
Member

mxschmitt commented Apr 3, 2020

HTMLInputElement

then something like that comes up, I also faced into this issue:

No overload matches this call.
  Overload 1 of 4, '(selector: string, pageFunction: PageFunctionOn<HTMLElement | HTMLInputElement | HTMLObjectElement | HTMLAnchorElement | HTMLAppletElement | ... 66 more ... | HTMLVideoElement, void, string>, arg?: any): Promise<...>', gave the following error.
    Argument of type '(el: HTMLInputElement) => string' is not assignable to parameter of type 'PageFunctionOn<HTMLElement | HTMLInputElement | HTMLObjectElement | HTMLAnchorElement | HTMLAppletElement | ... 66 more ... | HTMLVideoElement, void, string>'.
      Type '(el: HTMLInputElement) => string' is not assignable to type '(on: HTMLElement | HTMLInputElement | HTMLObjectElement | HTMLAnchorElement | HTMLAppletElement | ... 66 more ... | HTMLVideoElement, arg2: void) => string | Promise<...>'.
        Types of parameters 'el' and 'on' are incompatible.
          Type 'HTMLElement | HTMLInputElement | HTMLObjectElement | HTMLAnchorElement | HTMLAppletElement | ... 66 more ... | HTMLVideoElement' is not assignable to type 'HTMLInputElement'.
            Type 'HTMLElement' is missing the following properties from type 'HTMLInputElement': accept, align, alt, autocomplete, and 49 more.
  Overload 2 of 4, '(selector: string, pageFunction: PageFunctionOn<HTMLOrSVGElement, void, string>, arg?: any): Promise<string>', gave the following error.
    Argument of type '(el: HTMLInputElement) => string' is not assignable to parameter of type 'PageFunctionOn<HTMLOrSVGElement, void, string>'.
      Type '(el: HTMLInputElement) => string' is not assignable to type '(on: HTMLOrSVGElement, arg2: void) => string | Promise<string>'.
        Types of parameters 'el' and 'on' are incompatible.
          Type 'HTMLOrSVGElement' is not assignable to type 'HTMLInputElement'.
            Type 'SVGElement' is missing the following properties from type 'HTMLInputElement': accept, align, alt, autocomplete, and 69 more.

Something like that works:

page.$eval(selector, (el) => (el as HTMLInputElement).value)

@thernstig
Copy link
Contributor

thernstig commented Apr 4, 2020

If I am not mistaken, manual typing should work in this case:

await page.$eval('input[type=text]', (el: HTMLInputElement) => {
  el.value = '';
});

We are not using TypeScript. The reason we see the failures is because VS Code has type inference via their language service, so the above approach will not work for us.

@dgozman
Copy link
Contributor

dgozman commented Apr 11, 2020

@mxschmitt After #1747 (should be available in the upcoming playwright@next release), explicit (el: HTMLInputElement) => el.value should work.

@thernstig I am not sure what to do about VSCode being smart with javascript, but not allowing type annotations. Perhaps, JSDoc-style comments could help? Any ideas are welcome!

@thernstig
Copy link
Contributor

Yes maybe there is just so much VS Code can infer. We have a large code base and I haven't seen this problem with other code, but unfortunately I have got little knowledge of TypeScript so I also cannot be of much help as to why/how to solve this best. I hope to invest time in TypeScript soon enough to be able to be of better help with feedback such as this.

@pavelfeldman
Copy link
Member

This bug is now too big to track, let's close it as fixed and open new fine-grained bugs for the missing features!

aslushnikov added a commit to aslushnikov/playwright that referenced this issue Jul 21, 2020
This patch detects Chromium crash with a sandboxing error and re-writes
the error to surface information nicely.

```sh
pwuser@396166c88ec2:/root/playwright$ node a.js
(node:9916) UnhandledPromiseRejectionWarning: browserType.launch: Protocol error (Target.setAutoAttach): Target closed.
=========================== logs ===========================
[browser] <launching> /home/pwuser/.cache/ms-playwright/chromium-786218/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disab
le-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies --disable-hang-monitor --disab
le-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --user-data-dir=/tmp/playwrig
ht_chromiumdev_profile-S7DvGF --remote-debugging-pipe --headless --hide-scrollbars --mute-audio --no-startup-window
[browser] <launched> pid=9993
[browser] [0721/210028.684682:FATAL:zygote_host_impl_linux.cc(117)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live
dangerously and need an immediate workaround, you can try using --no-sandbox.
[browser] #0 0x55604e10fca9 base::debug::CollectStackTrace()
[browser] #1 0x55604e08abb3 base::debug::StackTrace::StackTrace()
[browser] microsoft#2 0x55604e09c810 logging::LogMessage::~LogMessage()
[browser] microsoft#3 0x55604c7e68de content::ZygoteHostImpl::Init()
[browser] microsoft#4 0x55604dc56067 content::ContentMainRunnerImpl::Initialize()
[browser] microsoft#5 0x55604dca493a service_manager::Main()
[browser] microsoft#6 0x55604dc54681 content::ContentMain()
[browser] microsoft#7 0x55604dca365d headless::(anonymous namespace)::RunContentMain()
[browser] microsoft#8 0x55604dca335c headless::HeadlessShellMain()
[browser] microsoft#9 0x55604b5a0527 ChromeMain
[browser] microsoft#10 0x7fcbfda52b97 __libc_start_main
[browser] microsoft#11 0x55604b5a036a _start
[browser]
[browser] Received signal 6
[browser] #0 0x55604e10fca9 base::debug::CollectStackTrace()
[browser] #1 0x55604e08abb3 base::debug::StackTrace::StackTrace()
[browser] microsoft#2 0x55604e10f845 base::debug::(anonymous namespace)::StackDumpSignalHandler()
[browser] microsoft#3 0x7fcc03ee3890 (/lib/x86_64-linux-gnu/libpthread-2.27.so+0x1288f)
[browser] microsoft#4 0x7fcbfda6fe97 gsignal
[browser] microsoft#5 0x7fcbfda71801 abort
[browser] microsoft#6 0x55604e10e7a5 base::debug::BreakDebugger()
[browser] microsoft#7 0x55604e09cc7b logging::LogMessage::~LogMessage()
[browser] microsoft#8 0x55604c7e68de content::ZygoteHostImpl::Init()
[browser] microsoft#9 0x55604dc56067 content::ContentMainRunnerImpl::Initialize()
[browser] microsoft#10 0x55604dca493a service_manager::Main()
[browser] microsoft#11 0x55604dc54681 content::ContentMain()
[browser] microsoft#12 0x55604dca365d headless::(anonymous namespace)::RunContentMain()
[browser] microsoft#13 0x55604dca335c headless::HeadlessShellMain()
[browser] microsoft#14 0x55604b5a0527 ChromeMain
[browser] microsoft#15 0x7fcbfda52b97 __libc_start_main
[browser] microsoft#16 0x55604b5a036a _start
[browser]   r8: 0000000000000000  r9: 00007fff94da5d90 r10: 0000000000000008 r11: 0000000000000246
[browser]  r12: 00007fff94da7060 r13: 00007fff94da5ff0 r14: 00007fff94da7070 r15: aaaaaaaaaaaaaaaa
[browser]   di: 0000000000000002  si: 00007fff94da5d90  bp: 00007fff94da5fe0  bx: 00007fff94da6824
[browser]   dx: 0000000000000000  ax: 0000000000000000  cx: 00007fcbfda6fe97  sp: 00007fff94da5d90
[browser]   ip: 00007fcbfda6fe97 efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
[browser]  trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[browser] [end of stack trace]
[browser] Calling _exit(1). Core file will not be generated.
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.Error
    at /root/playwright/lib/chromium/crConnection.js:131:63
    at new Promise (<anonymous>)
    at CRSession.send (/root/playwright/lib/chromium/crConnection.js:130:16)
    at CRSession.send (/root/playwright/lib/helper.js:78:31)
    at Function.connect (/root/playwright/lib/chromium/crBrowser.js:54:27)
    at Chromium._connectToTransport (/root/playwright/lib/server/chromium.js:53:38)
    at Chromium._innerLaunch (/root/playwright/lib/server/browserType.js:87:36)
    at async ProgressController.run (/root/playwright/lib/progress.js:75:28)
    at async Chromium.launch (/root/playwright/lib/server/browserType.js:60:25)
    at async /root/playwright/a.js:4:19
(node:9916) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejec
tion, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:9916) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```

```sh
pwuser@396166c88ec2:/root/playwright$ node a.js
(node:10074) UnhandledPromiseRejectionWarning: Chromium sandboxing failed!
================================
To workaround sandboxing issues, do either of the following:
  - (preferred): Configure environment to support sandboxing: https://github.com/microsoft/playwright/blob/master/docs/troubleshooting.md
  - (alternative): Launch Chromium without sandbox using 'chromiumSandbox: false' option
================================
Error
    at /root/playwright/lib/chromium/crConnection.js:131:63
    at new Promise (<anonymous>)
    at CRSession.send (/root/playwright/lib/chromium/crConnection.js:130:16)
    at CRSession.send (/root/playwright/lib/helper.js:78:31)
    at Function.connect (/root/playwright/lib/chromium/crBrowser.js:54:27)
    at Chromium._connectToTransport (/root/playwright/lib/server/chromium.js:53:38)
    at Chromium._innerLaunch (/root/playwright/lib/server/browserType.js:87:36)
    at async ProgressController.run (/root/playwright/lib/progress.js:75:28)
    at async Chromium.launch (/root/playwright/lib/server/browserType.js:60:25)
    at async /root/playwright/a.js:4:19
(node:10074) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:10074) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```
aslushnikov added a commit to aslushnikov/playwright that referenced this issue Jul 22, 2020
This patch detects Chromium crash with a sandboxing error and re-writes
the error to surface information nicely.

```sh
pwuser@396166c88ec2:/root/playwright$ node a.js
(node:9916) UnhandledPromiseRejectionWarning: browserType.launch: Protocol error (Target.setAutoAttach): Target closed.
=========================== logs ===========================
[browser] <launching> /home/pwuser/.cache/ms-playwright/chromium-786218/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disab
le-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies --disable-hang-monitor --disab
le-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --user-data-dir=/tmp/playwrig
ht_chromiumdev_profile-S7DvGF --remote-debugging-pipe --headless --hide-scrollbars --mute-audio --no-startup-window
[browser] <launched> pid=9993
[browser] [0721/210028.684682:FATAL:zygote_host_impl_linux.cc(117)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live
dangerously and need an immediate workaround, you can try using --no-sandbox.
[browser] #0 0x55604e10fca9 base::debug::CollectStackTrace()
[browser] #1 0x55604e08abb3 base::debug::StackTrace::StackTrace()
[browser] microsoft#2 0x55604e09c810 logging::LogMessage::~LogMessage()
[browser] microsoft#3 0x55604c7e68de content::ZygoteHostImpl::Init()
[browser] microsoft#4 0x55604dc56067 content::ContentMainRunnerImpl::Initialize()
[browser] microsoft#5 0x55604dca493a service_manager::Main()
[browser] microsoft#6 0x55604dc54681 content::ContentMain()
[browser] microsoft#7 0x55604dca365d headless::(anonymous namespace)::RunContentMain()
[browser] microsoft#8 0x55604dca335c headless::HeadlessShellMain()
[browser] microsoft#9 0x55604b5a0527 ChromeMain
[browser] microsoft#10 0x7fcbfda52b97 __libc_start_main
[browser] microsoft#11 0x55604b5a036a _start
[browser]
[browser] Received signal 6
[browser] #0 0x55604e10fca9 base::debug::CollectStackTrace()
[browser] #1 0x55604e08abb3 base::debug::StackTrace::StackTrace()
[browser] microsoft#2 0x55604e10f845 base::debug::(anonymous namespace)::StackDumpSignalHandler()
[browser] microsoft#3 0x7fcc03ee3890 (/lib/x86_64-linux-gnu/libpthread-2.27.so+0x1288f)
[browser] microsoft#4 0x7fcbfda6fe97 gsignal
[browser] microsoft#5 0x7fcbfda71801 abort
[browser] microsoft#6 0x55604e10e7a5 base::debug::BreakDebugger()
[browser] microsoft#7 0x55604e09cc7b logging::LogMessage::~LogMessage()
[browser] microsoft#8 0x55604c7e68de content::ZygoteHostImpl::Init()
[browser] microsoft#9 0x55604dc56067 content::ContentMainRunnerImpl::Initialize()
[browser] microsoft#10 0x55604dca493a service_manager::Main()
[browser] microsoft#11 0x55604dc54681 content::ContentMain()
[browser] microsoft#12 0x55604dca365d headless::(anonymous namespace)::RunContentMain()
[browser] microsoft#13 0x55604dca335c headless::HeadlessShellMain()
[browser] microsoft#14 0x55604b5a0527 ChromeMain
[browser] microsoft#15 0x7fcbfda52b97 __libc_start_main
[browser] microsoft#16 0x55604b5a036a _start
[browser]   r8: 0000000000000000  r9: 00007fff94da5d90 r10: 0000000000000008 r11: 0000000000000246
[browser]  r12: 00007fff94da7060 r13: 00007fff94da5ff0 r14: 00007fff94da7070 r15: aaaaaaaaaaaaaaaa
[browser]   di: 0000000000000002  si: 00007fff94da5d90  bp: 00007fff94da5fe0  bx: 00007fff94da6824
[browser]   dx: 0000000000000000  ax: 0000000000000000  cx: 00007fcbfda6fe97  sp: 00007fff94da5d90
[browser]   ip: 00007fcbfda6fe97 efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
[browser]  trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[browser] [end of stack trace]
[browser] Calling _exit(1). Core file will not be generated.
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.Error
    at /root/playwright/lib/chromium/crConnection.js:131:63
    at new Promise (<anonymous>)
    at CRSession.send (/root/playwright/lib/chromium/crConnection.js:130:16)
    at CRSession.send (/root/playwright/lib/helper.js:78:31)
    at Function.connect (/root/playwright/lib/chromium/crBrowser.js:54:27)
    at Chromium._connectToTransport (/root/playwright/lib/server/chromium.js:53:38)
    at Chromium._innerLaunch (/root/playwright/lib/server/browserType.js:87:36)
    at async ProgressController.run (/root/playwright/lib/progress.js:75:28)
    at async Chromium.launch (/root/playwright/lib/server/browserType.js:60:25)
    at async /root/playwright/a.js:4:19
(node:9916) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejec
tion, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:9916) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```

```sh
pwuser@396166c88ec2:/root/playwright$ node a.js
(node:10074) UnhandledPromiseRejectionWarning: Chromium sandboxing failed!
================================
To workaround sandboxing issues, do either of the following:
  - (preferred): Configure environment to support sandboxing: https://github.com/microsoft/playwright/blob/master/docs/troubleshooting.md
  - (alternative): Launch Chromium without sandbox using 'chromiumSandbox: false' option
================================
Error
    at /root/playwright/lib/chromium/crConnection.js:131:63
    at new Promise (<anonymous>)
    at CRSession.send (/root/playwright/lib/chromium/crConnection.js:130:16)
    at CRSession.send (/root/playwright/lib/helper.js:78:31)
    at Function.connect (/root/playwright/lib/chromium/crBrowser.js:54:27)
    at Chromium._connectToTransport (/root/playwright/lib/server/chromium.js:53:38)
    at Chromium._innerLaunch (/root/playwright/lib/server/browserType.js:87:36)
    at async ProgressController.run (/root/playwright/lib/progress.js:75:28)
    at async Chromium.launch (/root/playwright/lib/server/browserType.js:60:25)
    at async /root/playwright/a.js:4:19
(node:10074) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:10074) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```
aslushnikov added a commit that referenced this issue Jul 22, 2020
This patch detects Chromium crash with a sandboxing error and re-writes
the error to surface information nicely.

#### Error Before:

```sh
pwuser@23592d09b3bd:~/tmp$ node a.js
(node:324) UnhandledPromiseRejectionWarning: browserType.launch: Protocol error (Browser.getVersion): Target closed.
=========================== logs ===========================
[browser] <launching> /home/pwuser/.cache/ms-playwright/chromium-790602/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disab
le-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies --disable-hang-monitor --disab
le-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --user-data-dir=/tmp/playwrig
ht_chromiumdev_profile-mjSfr2 --remote-debugging-pipe --headless --hide-scrollbars --mute-audio --no-startup-window
[browser] <launched> pid=401
[browser] [0722/170825.030020:FATAL:zygote_host_impl_linux.cc(117)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live
dangerously and need an immediate workaround, you can try using --no-sandbox.
[browser] #0 0x55ac4f8c7be9 base::debug::CollectStackTrace()
[browser] #1 0x55ac4f841c13 base::debug::StackTrace::StackTrace()
[browser] #2 0x55ac4f853680 logging::LogMessage::~LogMessage()
[browser] #3 0x55ac4df2307e content::ZygoteHostImpl::Init()
[browser] #4 0x55ac4f40dd47 content::ContentMainRunnerImpl::Initialize()
[browser] #5 0x55ac4f45c9fa service_manager::Main()
[browser] #6 0x55ac4f40c361 content::ContentMain()
[browser] #7 0x55ac4f45b5bd headless::(anonymous namespace)::RunContentMain()
[browser] #8 0x55ac4f45b2bc headless::HeadlessShellMain()
[browser] #9 0x55ac4ccc22e7 ChromeMain
[browser] #10 0x7f0f3d736b97 __libc_start_main
[browser] #11 0x55ac4ccc212a _start
[browser]
[browser] Received signal 6
[browser] #0 0x55ac4f8c7be9 base::debug::CollectStackTrace()
[browser] #1 0x55ac4f841c13 base::debug::StackTrace::StackTrace()
[browser] #2 0x55ac4f8c7785 base::debug::(anonymous namespace)::StackDumpSignalHandler()
[browser] #3 0x7f0f437b3890 (/lib/x86_64-linux-gnu/libpthread-2.27.so+0x1288f)
[browser] #4 0x7f0f3d753e97 gsignal
[browser] #5 0x7f0f3d755801 abort
[browser] #6 0x55ac4f8c66e5 base::debug::BreakDebugger()
[browser] #7 0x55ac4f853aeb logging::LogMessage::~LogMessage()
[browser] #8 0x55ac4df2307e content::ZygoteHostImpl::Init()
[browser] #9 0x55ac4f40dd47 content::ContentMainRunnerImpl::Initialize()
[browser] #10 0x55ac4f45c9fa service_manager::Main()
[browser] #11 0x55ac4f40c361 content::ContentMain()
[browser] #12 0x55ac4f45b5bd headless::(anonymous namespace)::RunContentMain()
[browser] #13 0x55ac4f45b2bc headless::HeadlessShellMain()
[browser] #14 0x55ac4ccc22e7 ChromeMain
[browser] #15 0x7f0f3d736b97 __libc_start_main
[browser] #16 0x55ac4ccc212a _start
[browser]   r8: 0000000000000000  r9: 00007ffd38a863b0 r10: 0000000000000008 r11: 0000000000000246
[browser]  r12: 00007ffd38a87680 r13: 00007ffd38a86610 r14: 00007ffd38a87690 r15: aaaaaaaaaaaaaaaa
[browser]   di: 0000000000000002  si: 00007ffd38a863b0  bp: 00007ffd38a86600  bx: 00007ffd38a86e44
[browser]   dx: 0000000000000000  ax: 0000000000000000  cx: 00007f0f3d753e97  sp: 00007ffd38a863b0
[browser]   ip: 00007f0f3d753e97 efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
[browser]  trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[browser] [end of stack trace]
[browser] Calling _exit(1). Core file will not be generated.
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.Error
    at /home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:131:63
    at new Promise (<anonymous>)
    at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:130:16)
    at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/helper.js:78:31)
    at Function.connect (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crBrowser.js:54:39)
    at Chromium._connectToTransport (/home/pwuser/tmp/node_modules/playwright/lib/server/chromium.js:52:38)
    at Chromium._innerLaunch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:87:36)
    at async ProgressController.run (/home/pwuser/tmp/node_modules/playwright/lib/progress.js:75:28)
    at async Chromium.launch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:60:25)
    at async /home/pwuser/tmp/a.js:4:19
(node:324) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise reject
ion, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:324) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```


#### Error After:

```sh
pwuser@23592d09b3bd:~/tmp$ node a.js
(node:222) UnhandledPromiseRejectionWarning: browserType.launch: Chromium sandboxing failed!
================================
To workaround sandboxing issues, do either of the following:
  - (preferred): Configure environment to support sandboxing: https://github.com/microsoft/playwright/blob/master/docs/troubleshooting.md
  - (alternative): Launch Chromium without sandbox using 'chromiumSandbox: false' option
================================
Error
    at /home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:131:63
    at new Promise (<anonymous>)
    at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:130:16)
    at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/helper.js:78:31)
    at Function.connect (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crBrowser.js:54:27)
    at Chromium._connectToTransport (/home/pwuser/tmp/node_modules/playwright/lib/server/chromium.js:53:38)
    at Chromium._innerLaunch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:89:36)
    at async ProgressController.run (/home/pwuser/tmp/node_modules/playwright/lib/progress.js:75:28)
    at async Chromium.launch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:61:25)
    at async /home/pwuser/tmp/a.js:4:19
(node:222) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise reject
ion, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:222) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```

References #2745
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

5 participants