Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 18 additions & 2 deletions src/core/mentions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,24 @@ export async function parseMentions(
const markdown = await urlContentFetcher.urlToMarkdown(mention)
result = markdown
} catch (error) {
vscode.window.showErrorMessage(`Error fetching content for ${mention}: ${error.message}`)
result = `Error fetching content: ${error.message}`
console.error(`Error fetching URL ${mention}:`, error)

// Provide more helpful error messages based on error type
let errorMessage = error.message
if (error.message.includes("timeout")) {
errorMessage = `The website took too long to load (timeout). This could be due to a slow connection, heavy website, or the site being temporarily unavailable. You can try again later or check if the URL is correct.`
} else if (error.message.includes("net::ERR_NAME_NOT_RESOLVED")) {
errorMessage = `The website address could not be found. Please check if the URL is correct and try again.`
} else if (error.message.includes("net::ERR_INTERNET_DISCONNECTED")) {
errorMessage = `No internet connection. Please check your network connection and try again.`
} else if (error.message.includes("403") || error.message.includes("Forbidden")) {
errorMessage = `Access to this website is forbidden. The site may block automated access or require authentication.`
} else if (error.message.includes("404") || error.message.includes("Not Found")) {
errorMessage = `The page was not found. Please check if the URL is correct.`
}

vscode.window.showErrorMessage(`Error fetching content for ${mention}: ${errorMessage}`)
result = `Error fetching content: ${errorMessage}`
}
}
parsedText += `\n\n<url_content url="${mention}">\n${result}\n</url_content>`
Expand Down
6 changes: 3 additions & 3 deletions src/services/browser/BrowserSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export class BrowserSession {
* Navigate to a URL with standard loading options
*/
private async navigatePageToUrl(page: Page, url: string): Promise<void> {
await page.goto(url, { timeout: 7_000, waitUntil: ["domcontentloaded", "networkidle2"] })
await page.goto(url, { timeout: 15_000, waitUntil: ["domcontentloaded", "networkidle2"] })
await this.waitTillHTMLStable(page)
}

Expand Down Expand Up @@ -403,7 +403,7 @@ export class BrowserSession {
console.log(`Root domain: ${this.getRootDomain(currentUrl)}`)
console.log(`New URL: ${normalizedNewUrl}`)
return this.doAction(async (page) => {
await page.reload({ timeout: 7_000, waitUntil: ["domcontentloaded", "networkidle2"] })
await page.reload({ timeout: 15_000, waitUntil: ["domcontentloaded", "networkidle2"] })
await this.waitTillHTMLStable(page)
})
}
Expand Down Expand Up @@ -476,7 +476,7 @@ export class BrowserSession {
await page
.waitForNavigation({
waitUntil: ["domcontentloaded", "networkidle2"],
timeout: 7000,
timeout: 15000,
})
.catch(() => {})
await this.waitTillHTMLStable(page)
Expand Down
34 changes: 33 additions & 1 deletion src/services/browser/UrlContentFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,28 @@ export class UrlContentFetcher {
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",
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
"--no-first-run",
"--no-zygote",
"--disable-gpu",
"--disable-web-security",
"--disable-features=VizDisplayCompositor",
],
executablePath: stats.executablePath,
})
// (latest version of puppeteer does not add headless to user agent)
this.page = await this.browser?.newPage()

// Set additional page configurations to improve loading success
if (this.page) {
await this.page.setViewport({ width: 1280, height: 720 })
await this.page.setExtraHTTPHeaders({
"Accept-Language": "en-US,en;q=0.9",
})
}
}

async closeBrowser(): Promise<void> {
Expand All @@ -71,7 +88,22 @@ export class UrlContentFetcher {
- domcontentloaded is when the basic DOM is loaded
this should be sufficient for most doc sites
*/
await this.page.goto(url, { timeout: 10_000, waitUntil: ["domcontentloaded", "networkidle2"] })
try {
await this.page.goto(url, {
timeout: 30_000, // Increased from 10_000 to 30_000 (30 seconds)
waitUntil: ["domcontentloaded", "networkidle2"],
})
} catch (error) {
// If networkidle2 fails, try with just domcontentloaded as fallback
console.warn(
`Failed to load ${url} with networkidle2, retrying with domcontentloaded only: ${error.message}`,
)
await this.page.goto(url, {
timeout: 20_000, // 20 seconds for fallback
waitUntil: ["domcontentloaded"],
})
}

const content = await this.page.content()

// use cheerio to parse and clean up the HTML
Expand Down