updated headless for compatibility
This commit is contained in:
@@ -1904,7 +1904,7 @@ const AnimePlayer = (function() {
|
||||
animeId: _animeId,
|
||||
episode: _currentEpisode,
|
||||
entrySource: _entrySource
|
||||
};
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/watch/mpv', {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const { chromium } = require("playwright-chromium");
|
||||
let browser;
|
||||
let context;
|
||||
const BLOCK_LIST = [
|
||||
"google-analytics", "doubleclick", "facebook", "twitter",
|
||||
"adsystem", "analytics", "tracker", "pixel", "quantserve", "newrelic"
|
||||
@@ -23,10 +22,6 @@ async function initHeadless() {
|
||||
"--no-zygote",
|
||||
]
|
||||
});
|
||||
context = await browser.newContext({
|
||||
userAgent:
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/122.0.0.0 Safari/537.36"
|
||||
});
|
||||
}
|
||||
|
||||
async function turboScroll(page) {
|
||||
@@ -62,6 +57,12 @@ async function scrape(url, handler, options = {}) {
|
||||
loadImages = true
|
||||
} = options;
|
||||
if (!browser) await initHeadless();
|
||||
|
||||
const context = await browser.newContext({
|
||||
userAgent:
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/122.0.0.0 Safari/537.36"
|
||||
});
|
||||
|
||||
const page = await context.newPage();
|
||||
let collectedRequests = [];
|
||||
await page.route("**/*", (route) => {
|
||||
@@ -75,7 +76,7 @@ async function scrape(url, handler, options = {}) {
|
||||
resourceType: type
|
||||
});
|
||||
|
||||
if (type === "font" || type === "media" || type === "manifest")
|
||||
if (type === "font" || type === "manifest")
|
||||
return route.abort();
|
||||
|
||||
if (BLOCK_LIST.some(k => rUrl.includes(k)))
|
||||
@@ -86,6 +87,10 @@ async function scrape(url, handler, options = {}) {
|
||||
)) return route.abort();
|
||||
route.continue();
|
||||
});
|
||||
await page.addInitScript(() => {
|
||||
Object.defineProperty(navigator, "webdriver", { get: () => false });
|
||||
});
|
||||
|
||||
await page.goto(url, { waitUntil, timeout });
|
||||
if (waitSelector) {
|
||||
try {
|
||||
@@ -100,14 +105,12 @@ async function scrape(url, handler, options = {}) {
|
||||
}
|
||||
const result = await handler(page);
|
||||
await page.close();
|
||||
|
||||
await context.close();
|
||||
return { result, requests: collectedRequests };
|
||||
}
|
||||
|
||||
async function closeScraper() {
|
||||
if (context) await context.close();
|
||||
if (browser) await browser.close();
|
||||
context = null;
|
||||
browser = null;
|
||||
}
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user