puppeteer-detection-100-percent icon indicating copy to clipboard operation
puppeteer-detection-100-percent copied to clipboard

Interesting stuff

Open shtefcs opened this issue 3 years ago • 5 comments

Do you know if Puppeteer Extra package handles this? https://github.com/berstend/puppeteer-extra

shtefcs avatar May 01 '21 00:05 shtefcs

page.evaluateOnNewDocument(() => {

        class ModifiedError extends Error {

            constructor(message) {

                super(message)
                this.stack = this.stack.replace(
                    /at __puppeteer_evaluation_script__.*/gmi, 'at (window)'
                )

            }

        }

        Object.defineProperty(window, 'Error', { configurable: false, writable: false, value: ModifiedError })

})

checkmate =)

zelbov avatar Mar 02 '22 14:03 zelbov

page.evaluateOnNewDocument(() => {

        class ModifiedError extends Error {

            constructor(message) {

                super(message)
                this.stack = this.stack.replace(
                    /at __puppeteer_evaluation_script__.*/gmi, 'at (window)'
                )

            }

        }

        Object.defineProperty(window, 'Error', { configurable: false, writable: false, value: ModifiedError })

})

checkmate =)

Hey Vladislav, is that script stopping the detection of Puppeteer like it's stated by author of this repo?

shtefcs avatar Mar 03 '22 05:03 shtefcs

yep. it overlaps native Error object with child class which replaces detected string in stack trace on error initialization, and prevents further overlapping of Error object, before any other script will be executed on page

zelbov avatar Mar 04 '22 19:03 zelbov

yep. it overlaps native Error object with child class which replaces detected string in stack trace on error initialization, and prevents further overlapping of Error object, before any other script will be executed on page

Thank you for explanation!

shtefcs avatar Mar 05 '22 09:03 shtefcs

page.evaluateOnNewDocument(() => {

        class ModifiedError extends Error {

            constructor(message) {

                super(message)
                this.stack = this.stack.replace(
                    /at __puppeteer_evaluation_script__.*/gmi, 'at (window)'
                )

            }

        }

        Object.defineProperty(window, 'Error', { configurable: false, writable: false, value: ModifiedError })

})

checkmate =)

Any chance you can help with playwright version? I have used this

page.addInitScript(() => {
        class ModifiedError extends Error {
            constructor(message) {
                super(message)
                this.stack = this.stack.replace(
                    /at __playwright_evaluation_script__.*/gmi, 'at (window)'
                )
            }
        }        
        Object.defineProperty(window, 'Error', { configurable: false, writable: false, value: ModifiedError })        
    })

But than almost all youtube buttons stop working. For example when I click "upload" or "Youtube studio" nothing happens except bunch of errors in console.

tapistefan avatar Sep 19 '22 22:09 tapistefan