ChromeDevTools / devtools-protocol

Chrome DevTools Protocol
https://chromedevtools.github.io/devtools-protocol/
BSD 3-Clause "New" or "Revised" License
1.15k stars 226 forks source link

Using Debugger.setScriptSource function leads to browser crash #190

Closed DaveRingelnatz closed 4 years ago

DaveRingelnatz commented 5 years ago

Hey all,

I don't know if I am at the right place here, because I think the problem most probably lies in puppeteer but the issue template of puppeteer brought me here.

Problem description:

As soon as I try to use the Debugger.setScriptSource function, my Chromium crashes. Same happens, if I run the sample code on https://try-puppeteer.appspot.com/.

Sample script:

`const puppeteer = require('puppeteer');

(async() => { const browser = await puppeteer.launch(); const page = await browser.newPage();

let CDPsession = await page.target().createCDPSession();

let debuggerOn = await CDPsession.send('Debugger.enable');
if (debuggerOn) {
    await CDPsession.on('Debugger.scriptParsed', async scriptInfos => {
        try {
            let scriptSrc = await CDPsession.send('Debugger.getScriptSource', {
                scriptId: scriptInfos.scriptId
            });
            if (scriptSrc) {
                if (!scriptSrc.scriptSource.includes("__puppeteer_evaluation_script__")) {
                    console.log("-------------------------------------");
                    console.log("scriptId:", scriptInfos.scriptId);
                    console.log(scriptSrc.scriptSource);
                    let newScriptSrc = scriptSrc.scriptSource;
                    newScriptSrc = newScriptSrc.replace(/===/g, "==");
                    newScriptSrc = newScriptSrc.replace(/!==/g, "!=");
                    console.log("+++++++++++++++++++++");
                    console.log(newScriptSrc);
                    let test = await CDPsession.send('Debugger.setScriptSource', {
                        scriptId: scriptInfos.scriptId,
                        scriptSource: newScriptSrc,
                        dryRun: false,
                    }, function(err, msg) {
                        if (err)
                            console.log("Err with setScriptSource", scriptInfos.scriptId, msg.message);
                        else
                            console.log("setScriptSource successful:", msg);
                    });
                    console.log(test);
                }
            }
        } catch (getScriptSourceError) {
            console.log("getScriptSourceError:", getScriptSourceError);
        }
    });
}
await page.goto('http://google.com');
await browser.close();

})();`

(Code formatting does not work correctly somehow)

Error Message:

at Page._onTargetCrashed (/Users/.../node_modules/puppeteer/lib/Page.js:215:24) at CDPSession.Page.client.on.event (/Users/.../node_modules/puppeteer/lib/Page.js:123:56) at CDPSession.emit (events.js:193:13) at CDPSession._onMessage (/Users/.../node_modules/puppeteer/lib/Connection.js:200:12) at Connection._onMessage (/Users/.../node_modules/puppeteer/lib/Connection.js:112:17) at WebSocketTransport._ws.addEventListener.event (/Users/.../node_modules/puppeteer/lib/WebSocketTransport.js:44:24) at WebSocket.onMessage (/Users/.../node_modules/puppeteer/node_modules/ws/lib/event-target.js:120:16) at WebSocket.emit (events.js:193:13) at Receiver.receiverOnMessage (/Users/.../node_modules/puppeteer/node_modules/ws/lib/websocket.js:789:20) at Receiver.emit (events.js:193:13)

Any ideas what could be the problem?

Thanks and greetings

Dave

alexkozy commented 5 years ago

Most likely it is V8 live edit bug, please file this bug on crbug.com/v8. cc @hashseed

DaveRingelnatz commented 5 years ago

It seems to work now. I found out that I have to exclude internal puppeteer scripts from beeing changed which can be done like this (which is of course nowhere documented :) ):

if (scriptInfos.url !== '__puppeteer_evaluation_script__') {

Nevertheless I have 2 additional questions:

TimvdLippe commented 4 years ago

This repository is related to Chrome DevTools Protocol, but does not track issues regarding its definition or implementation. If you want to file an issue for the Chrome DevTools Protocol, please open an issue on https://crbug.com under component: Platform>DevTools>Platform. Thanks in advance!