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: export public types only #8584
Conversation
f9166f4
to
15e4342
Compare
Does this mean that it's not possible to access the A function that recursively unwraps handles unless they are handles to things that do not make sense unwrapped (functions, Nodes), which it leaves as JSHandles/ElementHandles. For example, it transforms async function unwrapHandle<T>(handle: JSHandle<T>): Promise<UnwrappedHandle<T>> {
return await unwrapHandleEx(handle, () => true) as UnwrappedHandle<T>;
}
async function unwrapHandleEx<T>(handle: JSHandle<T>, shouldUnwrap: (className: string) => boolean = className => ['Object', 'Proxy'].includes(className)):
Promise<UnwrappedHandleEx<T>> {
//XXX Replace _remoteObject with stable version if ever available
// Leave functions & symbols wrapped
if (['function', 'symbol'].includes(handle._remoteObject.type))
return handle as UnwrappedHandleEx<T>;
if (handle._remoteObject.type === 'object') {
if ([undefined, 'proxy'].includes(handle._remoteObject.subtype)) {
if (shouldUnwrap(handle._remoteObject.className!))
return Object.fromEntries(await Promise.all([...await handle.getProperties()]
.map(async ([k, v]) => [k, await unwrapHandleEx(v, shouldUnwrap)]))) as UnwrappedHandleEx<T>;
} else {
if (handle._remoteObject.subtype === 'null')
return null as UnwrappedHandleEx<T>;
if (handle._remoteObject.subtype === 'array')
return await Promise.all([...await handle.getProperties()]
.map(async ([, v]) => await unwrapHandleEx(v, shouldUnwrap))) as UnwrappedHandleEx<T>;
}
return handle as UnwrappedHandleEx<T>;
} else // Return other types such as numbers, booleans, bigints, etc. unwrapped
return (handle._remoteObject.type === 'undefined'
? undefined
: handle._remoteObject.value
?? (handle._remoteObject.unserializableValue
? eval(handle._remoteObject.unserializableValue) // You may want to use a map here instead
: await handle.jsonValue())) as UnwrappedHandleEx<T>; ( |
Another problem this created is that because Example where this is an issue: https://github.com/niieani/puppeteer-intercept-and-modify-requests/pull/4/files |
@jrandolf could you please take a look? I think it makes sense to export Protocol too and create a documented way to access the remote object. |
@niieani @stevenwdv Could you please file an issue for what you are requesting? |
This PR does a few things:
@internal
,@public
, etc).types.ts
file (originally calledapi-docs-entry.ts
) is auto-generated usingutils/export-all.js
.api-extractor
only extracts non-@internal
types.Puppeteer
are deprecated and encourage importing them directly from 'puppeteer'.