11import { Actor } from 'apify' ;
22import log from '@apify/log' ;
3- import type { Page } from 'puppeteer ' ;
4- import { inspect } from 'util' ;
3+ import type { CommonPage } from '@crawlee/browser-pool ' ;
4+ import { inspect } from 'node: util' ;
55import { RESOURCE_LOAD_ERROR_MESSAGE , SNAPSHOT } from './consts' ;
66import { createRandomHash } from './tools' ;
77
8+ export interface Page extends CommonPage {
9+ exposeFunction ( name : string , callback : ( ) => unknown ) : Promise < void > ;
10+ on ( eventName : string , handler : ( msg : any ) => Promise < void > ) : unknown ;
11+ content ( ) : unknown ;
12+ screenshot ( ) : unknown ;
13+ }
14+
815/**
916 * Creates a string with an appended pageFunction to be evaluated in
1017 * the browser context and placed within the given namespace.
@@ -97,10 +104,10 @@ export interface DumpConsoleOptions {
97104 *
98105 * This is used instead of the "dumpio" launch option
99106 * to prevent cluttering the STDOUT with unnecessary
100- * Chromium messages, usually internal errors, occuring in page.
107+ * Chromium messages, usually internal errors, occurring in page.
101108 */
102109export function dumpConsole ( page : Page , options : DumpConsoleOptions = { } ) {
103- page . on ( 'console' , async ( msg ) => {
110+ page . on ( 'console' , async ( msg : any ) => {
104111 const msgType = msg . type ( ) ;
105112
106113 if ( msgType === 'error' && ! options . logErrors ) return ;
@@ -116,12 +123,12 @@ export function dumpConsole(page: Page, options: DumpConsoleOptions = {}) {
116123 // Otherwise, just use the text immediately.
117124 let message ;
118125 if ( hasJSHandles ) {
119- const msgPromises = msg . args ( ) . map ( ( jsh ) => {
126+ const msgPromises = msg . args ( ) . map ( ( jsh : any ) => {
120127 return jsh . jsonValue ( )
121- . catch ( ( e ) => log . exception ( e , `Stringification of console.${ msgType } in browser failed.` ) ) ;
128+ . catch ( ( e : Error ) => log . exception ( e , `Stringification of console.${ msgType } in browser failed.` ) ) ;
122129 } ) ;
123130 message = ( await Promise . all ( msgPromises ) )
124- . map ( ( m ) => inspect ( m ) )
131+ . map ( ( m : string ) => inspect ( m ) )
125132 . join ( ' ' ) ; // console.log('a', 'b') produces 'a b'
126133 } else {
127134 message = msg . text ( ) ;
0 commit comments