Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/components/nodes/documentloaders/Cheerio/Cheerio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { parse } from 'css-what'
import { SelectorType } from 'cheerio'
import { ICommonObject, INodeOutputsValue, IDocument, INode, INodeData, INodeParams } from '../../../src/Interface'
import { handleEscapeCharacters, webCrawl, xmlScrape } from '../../../src/utils'
import { checkDenyList, secureFetch } from '../../../src/httpSecurity'

class Cheerio_DocumentLoaders implements INode {
label: string
Expand Down Expand Up @@ -148,13 +149,23 @@ class Cheerio_DocumentLoaders implements INode {

async function cheerioLoader(url: string): Promise<any> {
try {
await checkDenyList(url)
let docs: IDocument[] = []
if (url.endsWith('.pdf')) {
if (process.env.DEBUG === 'true')
options.logger.info(`[${orgId}]: CheerioWebBaseLoader does not support PDF files: ${url}`)
return docs
}
const loader = new CheerioWebBaseLoader(url, params)
loader.scrape = async () => {
const { load } = await CheerioWebBaseLoader.imports()
const response = await secureFetch(url, {
signal: loader.timeout ? AbortSignal.timeout(loader.timeout) : undefined,
headers: loader.headers
} as any)
const html = loader.textDecoder?.decode(await response.arrayBuffer()) ?? (await response.text())
return load(html)
}
if (textSplitter) {
docs = await loader.load()
docs = await textSplitter.splitDocuments(docs)
Expand Down
28 changes: 28 additions & 0 deletions packages/components/nodes/documentloaders/Playwright/Playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { test } from 'linkifyjs'
import { omit } from 'lodash'
import { handleEscapeCharacters, INodeOutputsValue, webCrawl, xmlScrape } from '../../../src'
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { checkDenyList } from '../../../src/httpSecurity'

class Playwright_DocumentLoaders implements INode {
label: string
Expand Down Expand Up @@ -189,6 +190,7 @@ class Playwright_DocumentLoaders implements INode {

async function playwrightLoader(url: string): Promise<Document[] | undefined> {
try {
await checkDenyList(url)
Comment thread
0xi4o marked this conversation as resolved.
let docs = []

const executablePath = process.env.PLAYWRIGHT_EXECUTABLE_PATH
Expand Down Expand Up @@ -224,6 +226,32 @@ class Playwright_DocumentLoaders implements INode {
}
}
const loader = new PlaywrightWebBaseLoader(url, config)
loader.scrape = async (): Promise<string> => {
const { chromium } = await PlaywrightWebBaseLoader.imports()
const browser = await chromium.launch({
headless: true,
...config.launchOptions
})
try {
const page = await browser.newPage()
await page.route('**', async (route, request) => {
try {
await checkDenyList(request.url())
await route.continue()
} catch {
await route.abort('blockedbyclient')
}
})
const response = await page.goto(url, {
timeout: 180000,
waitUntil: 'domcontentloaded',
...config.gotoOptions
})
return config.evaluate ? await config.evaluate(page, browser, response) : await page.content()
} finally {
await browser.close()
}
}
if (textSplitter) {
docs = await loader.load()
docs = await textSplitter.splitDocuments(docs)
Expand Down
31 changes: 31 additions & 0 deletions packages/components/nodes/documentloaders/Puppeteer/Puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { omit } from 'lodash'
import { PuppeteerLifeCycleEvent } from 'puppeteer'
import { handleEscapeCharacters, INodeOutputsValue, webCrawl, xmlScrape } from '../../../src'
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { checkDenyList } from '../../../src/httpSecurity'

class Puppeteer_DocumentLoaders implements INode {
label: string
Expand Down Expand Up @@ -180,6 +181,7 @@ class Puppeteer_DocumentLoaders implements INode {

async function puppeteerLoader(url: string): Promise<Document[] | undefined> {
try {
await checkDenyList(url)
Comment thread
0xi4o marked this conversation as resolved.
let docs: Document[] = []

const executablePath = process.env.PUPPETEER_EXECUTABLE_PATH
Expand Down Expand Up @@ -215,6 +217,35 @@ class Puppeteer_DocumentLoaders implements INode {
}
}
const loader = new PuppeteerWebBaseLoader(url, config)
loader.scrape = async (): Promise<string> => {
const { launch } = await PuppeteerWebBaseLoader.imports()
const browser = await launch({
headless: true,
defaultViewport: null,
ignoreDefaultArgs: ['--disable-extensions'],
...config.launchOptions
})
try {
const page = await browser.newPage()
await page.setRequestInterception(true)
page.on('request', async (interceptedRequest) => {
try {
await checkDenyList(interceptedRequest.url())
await interceptedRequest.continue()
} catch {
await interceptedRequest.abort('blockedbyclient')
}
})
await page.goto(url, {
timeout: 180000,
waitUntil: 'domcontentloaded',
...config.gotoOptions
})
return config.evaluate ? await config.evaluate(page, browser) : await page.evaluate(() => document.body.innerHTML)
} finally {
await browser.close()
}
}
if (textSplitter) {
docs = await loader.load()
docs = await textSplitter.splitDocuments(docs)
Expand Down
Loading