Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Protocol Mismatch #259

Open
IqroNegoro opened this issue Apr 19, 2024 · 11 comments
Open

[BUG] Protocol Mismatch #259

IqroNegoro opened this issue Apr 19, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@IqroNegoro
Copy link

IqroNegoro commented Apr 19, 2024

Environment

  • chromium Version: 123.0.1
  • puppeteer / puppeteer-core Version: 22.6.5
  • Node.js Version: 18.16.0
  • Lambda / GCF Runtime: 18.20.2

Expected Behavior

Puppeteer launched normally ( i run it at local first )

Current Behavior

Error: protocol mismatch after a while

Steps to Reproduce

the code is exactly same as example remote-min-binary

const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium-min");

const handler = async () => {
  try {
    const browser = await puppeteer.launch({
      args: chromium.args,
      defaultViewport: chromium.defaultViewport,
      executablePath: await chromium.executablePath(
        "https://github.com/Sparticuz/chromium/releases/download/v123.0.1/chromium-v123.0.1-pack.tar"
      ),
      headless: chromium.headless,
      ignoreHTTPSErrors: true,
    });

    const page = await browser.newPage();

    await page.goto("https://www.example.com", { waitUntil: "networkidle0" });

    console.log("Chromium:", await browser.version());
    console.log("Page Title:", await page.title());

    await page.close();

    await browser.close();
  } catch (error) {
    throw new Error(error.message);
  }
};

handler().then(() => console.log("Done"));

As i searched again, this package chromium-min is just for linux, is it true? can i used it in windows? i want to deploy it at netlify server cuz it limit was 50mb, then i try to using chromium-min and use external chromium (your github tar exactly), but it cannot launched as it normally
thx.

@IqroNegoro IqroNegoro added the bug Something isn't working label Apr 19, 2024
@IqroNegoro IqroNegoro changed the title [BUG] [BUG] Protocol Mismatch Apr 19, 2024
@jnmoons
Copy link

jnmoons commented Apr 22, 2024

same issue here, regardless if I use my own hosted version on azure blob storage or the github one:

async function getBrowser() {
    if (process.env.VERCEL_ENV === "production") {
        // Production settings on Vercel using the -min package
        const chromiumPackUrl = "https://privateblobstoragename.blob.core.windows.net/chromium-binaries/chromium-v121.0.0-pack.tar";
        const executablePath = await chromium.executablePath(chromiumPackUrl);
        return puppeteerCore.launch({
            args: chromium.args,
            defaultViewport: chromium.defaultViewport,
            executablePath,
            headless: chromium.headless, // true on server environments
        });
    } else {
        // Local development settings
        const localExecutablePath = process.env.CHROME_EXECUTABLE_PATH || 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe';
        return puppeteerCore.launch({
            executablePath: localExecutablePath,
            headless: true, // Set to false if you need a GUI
            args: ['--no-sandbox', '--disable-setuid-sandbox'],
        });
    }
}

I get this:

✓ Compiled /api/generate-pdf in 119ms (215 modules)
 ⨯ AssertionError [ERR_ASSERTION]: protocol mismatch
    at Object.request (C:\source\tml\tmladmin\tmladminui\node_modules\follow-redirects\index.js:530:14)
    at Object.get (C:\source\tml\tmladmin\tmladminui\node_modules\follow-redirects\index.js:537:44)
    at C:\source\tml\tmladmin\tmladminui\node_modules\@sparticuz\chromium-min\build\helper.js:56:10
    at new Promise (<anonymous>)
    at downloadAndExtract (C:\source\tml\tmladmin\tmladminui\node_modules\@sparticuz\chromium-min\build\helper.js:50:43)
    at Chromium.executablePath (C:\source\tml\tmladmin\tmladminui\node_modules\@sparticuz\chromium-min\build\index.js:244:78)
    at Chromium.executablePath (C:\source\tml\tmladmin\tmladminui\node_modules\@sparticuz\chromium-min\build\index.js:244:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getBrowser (webpack-internal:///(api)/./pages/api/generate-pdf.js:18:32)
    at async __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///(api)/./pages/api/generate-pdf.js:46:21) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: 'c:',
  expected: 'https:',
  operator: '==',
  page: '/api/generate-pdf'
}

on this line:

const executablePath = await chromium.executablePath(chromiumPackUrl);

running on localhost

the fact that it says

code: 'ERR_ASSERTION',
actual: 'c:',
expected: 'https:',
operator: '==',
page: '/api/generate-pdf'

with expected being https: and actual being c: makes it look like it is trying to access a local file, while the value of the chromiumPackUrl really is an https link

I have double checked the npm installed version is 121.0.0. Also tried with 123.0.1 as module and as tar file --> same result

@umutbozdag
Copy link

umutbozdag commented Apr 25, 2024

Same error here, any way to fix? @Sparticuz

@juliocarneiro
Copy link

same here

@AlejandroSanchez90
Copy link

same

@swizzmagik
Copy link

same issue

@saadmestaria
Copy link

Same here

@raulgodii
Copy link

same

@elBatel
Copy link

elBatel commented Jun 1, 2024

same issue

@raulgodii
Copy link

Finally I choose "Render" to host my App. You should use a Dockerfile to init Puppeteer. It was the only solution for this problem.

Reference:
https://www.youtube.com/watch?v=6cm6G78ZDmM&t=1s

FROM ghcr.io/puppeteer/puppeteer:22.10.0

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
    PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable

WORKDIR /usr/src/app

COPY package*.json ./
RUN npm ci
COPY . .
CMD [ "node", "api/index.js" ]```

@pnzzz
Copy link

pnzzz commented Oct 24, 2024

same issue pls

@Sparticuz
Copy link
Owner

This package is for Linux only. It will not work on windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests