英文:
Cannot find module puppeteer-core/internal/puppeteer-core.js in node_modules\puppeteer\lib\cjs\puppeteer\puppeteer.js when using browserify
问题
以下是您的翻译内容:
我试图使用browserify更改我的脚本,以在Chrome扩展中使用它,但它一直出现这个错误,我无法解决它。
[在此处输入图像描述](https://i.stack.imgur.com/242zk.jpg)
这是我的主要代码,我只希望这段代码能在Web扩展环境中工作,我尝试使用browserify,但它仍然出现图片中的问题。
const puppeteer = require('puppeteer');
const imdbScraper = require('easyimdbscraper');
const fs = require('fs');
// node popup.js
async function getMovieId(movieTitle) {
const browser = await puppeteer.launch({
headless: true,
userDataDir: "./tmp"
});
const page = await browser.newPage();
await page.goto(`https://www.google.com/search?q=${movieTitle}`);
const Handles = await page.$('.yuRUbf');
const anchorElement = await Handles.$('a');
const title = await page.evaluate(el => el.href, anchorElement)
const string = title;
const regex = /tt(\d+)/;
const match = string.match(regex);
let imdbId = match ? match[1] : null;
imdbId = "tt" + imdbId;
await browser.close();
return imdbId;
};
async function getInfoAboutMovie(movieId) {
var info = await imdbScraper.getInfoByID(movieId)
var infoJSON = JSON.stringify(info, null, 2); // JSON formatina dönüştürme ve düzgün bir şekilde formatlama
fs.writeFile('movie_info.json', infoJSON, 'utf8', () => {
console.log('Dosya başarıyla yazıldı: movie_info.json');
});
}
async function changeData() {
fs.readFile('./movie_info.json', 'utf8', (err, data) => {
if (err) {
console.error('Dosya okunamadı:', err);
return;
}
const info = JSON.parse(data);
const imgElement = document.querySelector(".resim");
imgElement.src = info.poster;
console.log("hello there");
});
}
async function main() {
let movieTitle = 'spiderman across';
movieTitle = movieTitle + " imdb";
var movieId = await getMovieId(movieTitle);
await getInfoAboutMovie(movieId);
await changeData();
}
main();
希望这有助于您的项目。如果您有任何其他疑问,请随时提出。
英文:
I'm trying to change my script with browserify to use it in chrome extension, but it keeps giving this error and I couldn't solve it.
enter image description here
this is my main code, all I want is for this code to work in the web extension environment, I tried using browserify for this, but it continues to give the problem in the picture.
const puppeteer = require('puppeteer');
const imdbScraper = require('easyimdbscraper')
const fs = require('fs');
// node popup.js
async function getMovieId (movieTitle) {
const browser = await puppeteer.launch({
headless: true,
userDataDir: "./tmp"
});
const page = await browser.newPage();
await page.goto(`https://www.google.com/search?q=${movieTitle}`);
const Handles = await page.$('.yuRUbf');
const anchorElement = await Handles.$('a');
const title = await page.evaluate(el => el.href,anchorElement)
const string = title;
const regex = /tt(\d+)/;
const match = string.match(regex);
let imdbId = match ? match[1] : null;
imdbId = "tt" + imdbId;
await browser.close();
return imdbId;
};
async function getInfoAboutMovie (movieId) {
var info = await imdbScraper.getInfoByID(movieId)
var infoJSON = JSON.stringify(info, null, 2); // JSON formatina dönüştürme ve düzgün bir şekilde formatlama
fs.writeFile('movie_info.json', infoJSON, 'utf8', () => {
console.log('Dosya başariyla yazildi: movie_info.json');
});
}
async function changeData() {
fs.readFile('./movie_info.json', 'utf8', (err, data) => {
if (err) {
console.error('Dosya okunamadı:', err);
return;
}
const info = JSON.parse(data);
const imgElement = document.querySelector(".resim");
imgElement.src = info.poster;
console.log("hello there");
});
}
async function main() {
let movieTitle = 'spiderman across';
movieTitle = movieTitle + " imdb";
var movieId = await getMovieId(movieTitle);
await getInfoAboutMovie(movieId);
await changeData();
}
main();
答案1
得分: 1
npm i puppeteer@18.1.0
英文:
When I put puppeteer to the following version and tried it, the problem was solved for the moment:
npm i puppeteer@18.1.0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论