deno-puppeteer icon indicating copy to clipboard operation
deno-puppeteer copied to clipboard

$eval and $$eval TypeScript return types incorrectly wrap all values in ElementHandle

Open FeldrinH opened this issue 3 years ago • 1 comments

The return value of $eval and $$eval should only be wrapped in an ElementHandle when they are of type Element. However, the TypeScript return types of these functions indicate that all return values are wrapped in ElementHandles, regardless of their types.

The problems seems to come from this line: https://github.com/lucacasonato/deno-puppeteer/blob/14.1.1/vendor/puppeteer-core/puppeteer/common/EvalTypes.d.ts#L66

In the upstream puppeteer repo this line correctly checks if the type extends Element before wrapping it in an ElementHandle (https://github.com/puppeteer/puppeteer/blob/v14.1.1/src/common/EvalTypes.ts#L75), but in this deno port, the type Element is replaced with the type any, causing the aforementioned bug.

FeldrinH avatar Jun 07 '22 09:06 FeldrinH

The same is happening in common/types.d.ts with HandleFor<T>, causing Page.evaluateHandle to return the incorrect type. I wonder why Node and Element are replaced with any, I reckon it's because Deno doesn't have these types built in. But these are .d.ts files, you'd think this should work fine with "lib": ["dom"] in the compiler options.

jespertheend avatar Sep 10 '22 21:09 jespertheend