puppeteer/packages/puppeteer-core/src
Joe Gomain Hoyes bef1061c06
feat(puppeteer-core): Infer element type from complex selector (#9253)
**What kind of change does this PR introduce?**

Better type inference.

**Did you add tests for your changes?**

~Not yet.~ Yes.

**If relevant, did you update the documentation?**

Not yet.

**Summary**

<!-- Explain the **motivation** for making this change. What existing
problem does the pull request solve? -->
<!-- Try to link to an open issue for more information. -->
Currently methods that return an element handle, i.e. `.$`,
`.waitForSelector` attempt to infer the node element type from the
selector string. However, this only works when the selector is an exact
match of the element tag, i.e. a selector `"a"` would be inferred as
`HTMLAnchorElement` . And not when the selector is complex, i.e.
selectors `"a#some-id"`, `div > a`, `a:nth-child(2)` would all fallback
on `Element`.

This is due to simply looking up the the selector in
`HTMLElementTagNameMap` and `SVGElementTagNameMap` without any attempt
to parse the selector string.

This PR is an attempt to do so.

**Does this PR introduce a breaking change?**

<!-- If this PR introduces a breaking change, please describe the impact
and a migration path for existing applications. -->
This could break existing incorrect assertions using the `as` keyword.

**Other information**

~This PR introduces a dependency on the `type-fest` package.~

This PR is far from complete (no tests, no docs). Put out early for
feedback and discussion.

Co-authored-by: Alex Rudenko <OrKoN@users.noreply.github.com>
2022-11-23 10:59:23 +01:00
..
api docs: fix typo in Viewport fields (#9293) 2022-11-17 17:27:07 +01:00
common feat(puppeteer-core): Infer element type from complex selector (#9253) 2022-11-23 10:59:23 +01:00
injected fix: remove boundary conditions for visibility (#9249) 2022-11-14 09:34:07 +01:00
node chore: re-export all exports (#9241) 2022-11-10 17:11:18 +01:00
templates feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
util chore: re-export all exports (#9241) 2022-11-10 17:11:18 +01:00
environment.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
puppeteer-core.ts chore: re-export all exports (#9241) 2022-11-10 17:11:18 +01:00
revisions.ts feat(chromium): roll to Chromium 108.0.5351.0 (r1056772) (#9153) 2022-10-25 12:55:19 +02:00
tsconfig.cjs.json feat!: use ~/.cache/puppeteer for browser downloads (#9095) 2022-10-11 11:20:45 +00:00
tsconfig.esm.json feat!: use ~/.cache/puppeteer for browser downloads (#9095) 2022-10-11 11:20:45 +00:00