puppeteer/packages/puppeteer-core/src/common
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
..
bidi chore: re-export all exports (#9241) 2022-11-10 17:11:18 +01:00
Accessibility.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
AriaQueryHandler.ts chore: re-export all exports (#9241) 2022-11-10 17:11:18 +01:00
Browser.ts feat: expose browser context id (#9134) 2022-10-19 08:30:57 +00:00
BrowserConnector.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
BrowserWebSocketTransport.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
ChromeTargetManager.ts chore: remove special handling for shared_worker (#9096) 2022-10-11 12:18:06 +00:00
common.ts chore: re-export all exports (#9241) 2022-11-10 17:11:18 +01:00
Configuration.ts fix: update documentation on configuring puppeteer (#9150) 2022-10-24 09:07:05 +02:00
Connection.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
ConnectionTransport.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
ConsoleMessage.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
Coverage.ts feat: add ability to collect JS code coverage at the function level (#9027) 2022-10-06 23:53:05 +02:00
Debug.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
Device.ts fix!: remove puppeteer.devices in favor of KnownDevices (#9075) 2022-10-10 15:30:12 +02:00
Dialog.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
ElementHandle.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
EmulationManager.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
Errors.ts fix!: deprecate indirect error imports (#9072) 2022-10-06 23:52:51 +02:00
EventEmitter.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
ExecutionContext.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
fetch.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
FileChooser.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
FirefoxTargetManager.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
Frame.ts chore: re-export all exports (#9241) 2022-11-10 17:11:18 +01:00
FrameManager.ts chore: re-export all exports (#9241) 2022-11-10 17:11:18 +01:00
FrameTree.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
HTTPRequest.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
HTTPResponse.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
Input.ts chore: improve docs and scripts (#9107) 2022-10-13 18:55:11 +02:00
IsolatedWorld.ts chore: re-export all exports (#9241) 2022-11-10 17:11:18 +01:00
IsolatedWorlds.ts chore: re-export all exports (#9241) 2022-11-10 17:11:18 +01:00
JSHandle.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
LazyArg.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
LifecycleWatcher.ts fix: resolve navigation requests when request fails (#9178) 2022-10-28 09:56:06 +02:00
NetworkEventManager.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
NetworkManager.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
NodeWebSocketTransport.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
Page.ts docs: fix typo in Viewport fields (#9293) 2022-11-17 17:27:07 +01:00
PDFOptions.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
PredefinedNetworkConditions.ts fix!: deprecate indirect network condition imports (#9074) 2022-10-06 23:52:58 +02:00
Product.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
Puppeteer.ts feat: use configuration files (#9140) 2022-10-21 15:09:21 +02:00
PuppeteerViewport.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
QueryHandler.ts chore: re-export all exports (#9241) 2022-11-10 17:11:18 +01:00
SecurityDetails.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
Target.ts chore: extract BrowserContext to its own file (#9133) 2022-10-19 07:06:31 +00:00
TargetManager.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
TaskQueue.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
TimeoutSettings.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
Tracing.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
types.ts feat(puppeteer-core): Infer element type from complex selector (#9253) 2022-11-23 10:59:23 +01:00
USKeyboardLayout.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
util.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
WaitTask.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00
WebWorker.ts feat: separate puppeteer and puppeteer-core (#9023) 2022-10-05 14:17:03 +02:00