PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
8.83k stars 314 forks source link

[BUG] Using PDF.js (pdfjs-dist) in Plasmo project generates file with name "_empty.<random number>.js" that is reserved by the system #936

Open felixswang opened 2 months ago

felixswang commented 2 months ago

What happened?

Tried in both background index.ts and content scripts, both have the issue.

My code:

import * as pdfjsLib from 'pdfjs-dist';

pdfjsLib.GlobalWorkerOptions.workerSrc = `//mozilla.github.io/pdf.js/build/pdf.worker.js`;

const pdf = await pdfjsLib.getDocument(msg.pdfUrl).promise;

const numPages = pdf.numPages;

let fullText = '';

for (let pageNumber = 1; pageNumber <= numPages; pageNumber++) {
    const page = await pdf.getPage(pageNumber);
    const textContent = await page.getTextContent();
    textContent.items.forEach(item => {
        fullText += item.str;
    });
}

When the extension is compiled and loaded in Chrome, Chrome pops an alert saying:

Failed to load extension File ~/Products/GPTPlugin/gpt-plugin/build/chrome-mv3-dev Error Cannot load extension with file or directory name _empty.c3437ec2.js. Filenames starting with "_" are reserved for use by the system. Could not load manifest.

Version

Latest

What OS are you seeing the problem on?

MacOSX

What browsers are you seeing the problem on?

Chrome

Relevant log output

No log because the error occurs when the extension is loaded

(OPTIONAL) Contribution

Code of Conduct

felixswang commented 2 months ago

Is there any update regarding this bug?

123wwwa commented 2 months ago

I have same issue using pdfjs-dist

123wwwa commented 2 months ago

I solved error by using import { pdfjs } from "react-pdf" pdfjs.GlobalWorkerOptions.workerSrc = //cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js instead of import * as pdfjs from 'pdfjs-dist'

muqsitnawaz commented 1 month ago

Same here. Tried a few different packages pdfjs-dist, pdf-text-reader, couldn't get any of these pdf readers to extract text when using Plasmo.

What's the purpose of _empty file and why is plasmo generating it?

lkuo117 commented 1 week ago

Experiencing the same issue with pdfjs-dist. On Plasmo v0.86.2