critical icon indicating copy to clipboard operation
critical copied to clipboard

critical does not work with a remote browser

Open thasmo opened this issue 5 years ago • 6 comments

Running something like this doesn't work.

const browser = puppeteer.connect({
    browserWSEndpoint: 'ws://127.0.0.1:3000',
});

critical.generate({
    src: 'https://www.google.com/',
    penthouse: {
        puppeteer: {
            getBrowser: () => browser,
        },
    },
});

This results in an error.

{
    "errorMessage": "Protocol error (Page.navigate): Cannot navigate to invalid URL",
    "errorType": "Error",
    "stackTrace": [
        "Error: Protocol error (Page.navigate): Cannot navigate to invalid URL",
        "at Promise (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\Connection.js:185:56)",
        "at new Promise (<anonymous>)",
        "at CDPSession.send (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\Connection.js:184:12)",
        "at navigate (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\FrameManager.js:119:39)",
        "at FrameManager.navigateFrame (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\FrameManager.js:96:7)",
        "at Frame.goto (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\FrameManager.js:407:37)",
        "at Frame.<anonymous> (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\helper.js:111:23)",
        "at Page.goto (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\Page.js:629:49)",
        "at Page.<anonymous> (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\helper.js:111:23)",
        "at loadPage (C:\\Users\\user\\Projects\\project\\node_modules\\penthouse\\lib\\core.js:54:30)",
        "at Promise (C:\\Users\\user\\Projects\\project\\node_modules\\penthouse\\lib\\core.js:384:29)",
        "at process._tickCallback (internal/process/next_tick.js:68:7)"
    ]
}

It tries to connect to 'file://C:\\Users\\user\\AppData\\Local\\Temp\\6df8ea397e6c2d676ff1b27a1e00f391\\79f06439b62759c632b77f71ef3d3cd0.html'.

Would it somehow be possible to get this working using a remote browser? I'm running a headless chrome instance in a docker container which I let puppeteer connect to and it obviously can't connect to a local temp file.

thasmo avatar Jun 12 '19 17:06 thasmo

Could you try with penthouse directly, to see if the error has anything to do with the critical package or not? It might not; if so could you raise the issue in the Penthouse repo instead? Cheers

pocketjoso avatar Jun 13 '19 10:06 pocketjoso

@pocketjoso, afaik critical creates a temporary local file which is passed to penthouse instead of the actual/original address. At least that's what I think is happening. The reasons for this I don't know but I guess it's to yield better results from penthouse.

thasmo avatar Jun 13 '19 18:06 thasmo

@thasmo: I just made some changes which hopefully fix this. Would you give it another try with v2.0.0.19? Unfortunately, i have no computer running windows so i it may result in some try & error until we get this fixed ;)

bezoerb avatar Jun 18 '19 21:06 bezoerb

@bezoerb I've tested it and the error message changed.

{
    "errorMessage": "net::ERR_FILE_NOT_FOUND at file:///C:/Users/user/AppData/Local/Temp/954492307c4418a290d6d4164df58aef/efc9e528d5ccf06a86532443cd2b4e0f.html",
    "errorType": "Error",
    "stackTrace": [
        "Error: net::ERR_FILE_NOT_FOUND at file:///C:/Users/user/AppData/Local/Temp/954492307c4418a290d6d4164df58aef/efc9e528d5ccf06a86532443cd2b4e0f.html",
        "    at navigate (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\FrameManager.js:121:37)",
        "    at process._tickCallback (internal/process/next_tick.js:68:7)",
        "  -- ASYNC --",
        "    at Frame.<anonymous> (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\helper.js:110:27)",
        "    at Page.goto (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\Page.js:629:49)",
        "    at Page.<anonymous> (C:\\Users\\user\\Projects\\project\\node_modules\\puppeteer-core\\lib\\helper.js:111:23)",
        "    at loadPage (C:\\Users\\user\\Projects\\project\\node_modules\\penthouse\\lib\\core.js:54:30)",
        "    at Promise (C:\\Users\\user\\Projects\\project\\node_modules\\penthouse\\lib\\core.js:384:29)",
        "    at process._tickCallback (internal/process/next_tick.js:68:7)"
    ]
}

I've looked at your commit and I'm not sure the actual issue is about generating the correct path to the file. What I mean is that critical, when using a remote headless chrome (a chrome instance running on a remote location/machine), does not work at all, because critical creates a local temporary file, but the remote machine has no way of accessing the file at all, because the temporary file does not exist on the filesystem of the remote machine.

This is probably a more profound issue and won't be resolved easily, I guess.

thasmo avatar Jun 20 '19 07:06 thasmo

Ahhh, now I get it 😊 I must have missed the “remote” path...

bezoerb avatar Jun 20 '19 07:06 bezoerb

@thasmo did you manage to solve the problem?

bushido-js avatar Mar 14 '23 12:03 bushido-js