Skip to content
Merged
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
21 changes: 13 additions & 8 deletions src/services/browser/UrlContentFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,20 @@ export class UrlContentFetcher {
return
}
const stats = await this.ensureChromiumExists()
const args = [
"--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
"--no-first-run",
"--disable-gpu",
"--disable-features=VizDisplayCompositor",
]
if (process.platform === "linux") {
// Fixes network errors on Linux hosts (see https://github.com/puppeteer/puppeteer/issues/8246)
args.push("--no-sandbox")
}
this.browser = await stats.puppeteer.launch({
args: [
"--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
"--no-first-run",
"--disable-gpu",
"--disable-features=VizDisplayCompositor",
],
args,
executablePath: stats.executablePath,
})
// (latest version of puppeteer does not add headless to user agent)
Expand Down
82 changes: 66 additions & 16 deletions src/services/browser/__tests__/UrlContentFetcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,75 @@ describe("UrlContentFetcher", () => {
})

describe("launchBrowser", () => {
it("should launch browser with correct arguments", async () => {
await urlContentFetcher.launchBrowser()

expect(vi.mocked(PCR)).toHaveBeenCalledWith({
downloadPath: path.join("/test/storage", "puppeteer"),
it("should launch browser with correct arguments on non-Linux platforms", async () => {
// Ensure we're not on Linux for this test
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'darwin' // macOS
})

const stats = await vi.mocked(PCR).mock.results[0].value
expect(stats.puppeteer.launch).toHaveBeenCalledWith({
args: [
"--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
"--no-first-run",
"--disable-gpu",
"--disable-features=VizDisplayCompositor",
],
executablePath: "/path/to/chromium",
try {
await urlContentFetcher.launchBrowser()

expect(vi.mocked(PCR)).toHaveBeenCalledWith({
downloadPath: path.join("/test/storage", "puppeteer"),
})

const stats = await vi.mocked(PCR).mock.results[0].value
expect(stats.puppeteer.launch).toHaveBeenCalledWith({
args: [
"--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
"--no-first-run",
"--disable-gpu",
"--disable-features=VizDisplayCompositor",
],
executablePath: "/path/to/chromium",
})
} finally {
// Restore original platform
Object.defineProperty(process, 'platform', {
value: originalPlatform
})
}
})

it("should launch browser with Linux-specific arguments", async () => {
// Mock process.platform to be linux
const originalPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'linux'
})

try {
// Create a new instance to ensure fresh state
const linuxFetcher = new UrlContentFetcher(mockContext)
await linuxFetcher.launchBrowser()

expect(vi.mocked(PCR)).toHaveBeenCalledWith({
downloadPath: path.join("/test/storage", "puppeteer"),
})

const stats = await vi.mocked(PCR).mock.results[vi.mocked(PCR).mock.results.length - 1].value
expect(stats.puppeteer.launch).toHaveBeenCalledWith({
args: [
"--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
"--no-first-run",
"--disable-gpu",
"--disable-features=VizDisplayCompositor",
"--no-sandbox", // Linux-specific argument
],
executablePath: "/path/to/chromium",
})
} finally {
// Restore original platform
Object.defineProperty(process, 'platform', {
value: originalPlatform
})
}
})

it("should set viewport and headers after launching", async () => {
Expand Down
Loading