peterbe / minimalcss

Extract the minimal CSS used in a set of URLs with puppeteer
https://minimalcss.app/
MIT License
353 stars 35 forks source link

Failed the minimize CSS: Error: Protocol error (Emulation.setDeviceMetricsOverride) #340

Open homanp opened 4 years ago

homanp commented 4 years ago

Hi there @peterbe!

I'm trying to use your module with my own instance of puppeteer. My code looks like so:

'use strict'
const chrome = require('chrome-aws-lambda');
const puppeteer = require('puppeteer-core');
const miminalcss = require('minimalcss');

const url = 'https://www.google.com';
let minimalCss = '';

const browser = await puppeteer.launch({
    args: chrome.args,
    executablePath: await chrome.executablePath,
    headless: chrome.headless
});

miminalcss.minimize({urls: [url], browser})
    .then(result => {
        minimalCss = result.finalCss;
    })
    .catch(error => {
        console.error(`Failed the minimize CSS: ${error}`);
    });

ERROR: RROR Failed the minimize CSS: Error: Protocol error (Emulation.setDeviceMetricsOverride): Session closed. Most likely the page has been closed.

DEPENDENCIES:

"chrome-aws-lambda": "^2.0.0",
"minimalcss": "^0.8.3",
"puppeteer-core": "^2.0.0",

Any ideas on what the issue might be? Seems like the connection is getting closed for some reason.

Thanks!

peterbe commented 4 years ago

I don't know how I didn't see this until now! To be honest, I actually don't know how to debug this. I tried to edit your demo code by switching from puppeteer-core to puppeteer but I keep getting this:

▶ node index.js
Failed the minimize CSS: Error: DOMException: A network error occurred.

A Chromium window does appear with nothing in the Web console.

Screen Shot 2020-01-23 at 12 55 47 PM

Perhaps a bunch of dependencies have changed enough to not be able to reproduce. Perhaps I just don't understand how to use chrome-aws-lambda and puppeteer-core. Perhaps you can injects some debugging and try to understand why it's throwing like that.