mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Allow image and media to be loaded in puppeteer
This commit is contained in:
parent
1a1617e86c
commit
d816ee9563
3 changed files with 6 additions and 33 deletions
|
|
@ -93,7 +93,7 @@ export const createPageSaveRequest = async (
|
|||
url: normalizedUrl,
|
||||
})
|
||||
if (page) {
|
||||
console.log('Page already exists', page)
|
||||
console.log('Page already exists', page.id, page.url)
|
||||
articleSavingRequestId = page.id
|
||||
} else {
|
||||
page = {
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ export const parsePreparedContent = async (
|
|||
return {
|
||||
canonicalUrl: url,
|
||||
parsedContent: null,
|
||||
domContent: preparedDocument.document,
|
||||
domContent: document,
|
||||
pageType: PageType.Unknown,
|
||||
}
|
||||
}
|
||||
|
|
@ -223,7 +223,7 @@ export const parsePreparedContent = async (
|
|||
if (!article?.textContent && allowRetry) {
|
||||
const newDocument = {
|
||||
...preparedDocument,
|
||||
document: '<html>' + preparedDocument.document + '</html>',
|
||||
document: '<html>' + document + '</html>',
|
||||
}
|
||||
return parsePreparedContent(
|
||||
url,
|
||||
|
|
@ -337,7 +337,7 @@ export const parsePreparedContent = async (
|
|||
logger.info('parse-article completed')
|
||||
|
||||
return {
|
||||
domContent: preparedDocument.document,
|
||||
domContent: document,
|
||||
parsedContent: article,
|
||||
canonicalUrl,
|
||||
pageType: parseOriginalContent(dom),
|
||||
|
|
|
|||
|
|
@ -409,32 +409,6 @@ function getUrl(req) {
|
|||
return parsed.href;
|
||||
}
|
||||
|
||||
async function blockResources(client) {
|
||||
const blockedResources = [
|
||||
// Assets
|
||||
// '*/favicon.ico',
|
||||
// '.css',
|
||||
// '.jpg',
|
||||
// '.jpeg',
|
||||
// '.png',
|
||||
// '.svg',
|
||||
// '.woff',
|
||||
|
||||
// Analytics and other fluff
|
||||
'*.optimizely.com',
|
||||
'everesttech.net',
|
||||
'userzoom.com',
|
||||
'doubleclick.net',
|
||||
'googleadservices.com',
|
||||
'adservice.google.com/*',
|
||||
'connect.facebook.com',
|
||||
'connect.facebook.net',
|
||||
'sp.analytics.yahoo.com',
|
||||
]
|
||||
|
||||
await client.send('Network.setBlockedURLs', { urls: blockedResources });
|
||||
}
|
||||
|
||||
async function retrievePage(url, logRecord, functionStartTime) {
|
||||
validateUrlString(url);
|
||||
|
||||
|
|
@ -494,8 +468,6 @@ async function retrievePage(url, logRecord, functionStartTime) {
|
|||
} catch {}
|
||||
});
|
||||
|
||||
await blockResources(client);
|
||||
|
||||
/*
|
||||
* Disallow MathJax from running in Puppeteer and modifying the document,
|
||||
* we shall instead run it in our frontend application to transform any
|
||||
|
|
@ -504,7 +476,8 @@ async function retrievePage(url, logRecord, functionStartTime) {
|
|||
await page.setRequestInterception(true);
|
||||
let requestCount = 0;
|
||||
page.on('request', request => {
|
||||
if (['font', 'image', 'media'].includes(request.resourceType())) {
|
||||
if (request.resourceType() === 'font') {
|
||||
// Disallow fonts from loading
|
||||
request.abort();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue