Skip to content

Commit 189c35f

Browse files
sjhuclaude
andcommitted
fix(perplexity-web): click "New Thread" button for fresh search
Instead of navigating to home page (which may keep old context), click the "新建问题" button to start a fresh search thread. Also compare URL before/after submit to detect actual navigation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 384eea6 commit 189c35f

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

‎src/zero-token/providers/perplexity-web-client-browser.ts‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,20 @@ export class PerplexityWebClientBrowser {
146146
// Perplexity's /search API now returns HTML, not SSE, so we interact via DOM.
147147
const page = this.page;
148148

149-
// Always navigate to home page for a fresh search
150-
await page.goto("https://www.perplexity.ai/", { waitUntil: "domcontentloaded" });
151-
await page.waitForTimeout(2000);
149+
// Click "新建问题" (New Thread) to start a fresh search.
150+
// This is more reliable than navigating to home page.
151+
const newThreadBtn = await page.$(
152+
'button:has-text("新建问题"), button:has-text("New Thread"), a:has-text("新建问题"), a:has-text("New Thread")',
153+
);
154+
if (newThreadBtn) {
155+
await newThreadBtn.click();
156+
console.log("[Perplexity Web Browser] Clicked 'New Thread' button");
157+
await page.waitForTimeout(1500);
158+
} else {
159+
// Fallback: navigate to home page
160+
await page.goto("https://www.perplexity.ai/", { waitUntil: "domcontentloaded" });
161+
await page.waitForTimeout(2000);
162+
}
152163

153164
// Find and focus the input
154165
const inputSel = 'div[contenteditable="true"], [role="textbox"], textarea';
@@ -162,17 +173,23 @@ export class PerplexityWebClientBrowser {
162173
// Clear any residual text, then type message
163174
await page.keyboard.press("Meta+a");
164175
await page.keyboard.press("Backspace");
176+
await page.waitForTimeout(200);
165177
await page.keyboard.type(message, { delay: 20 });
166178
await page.waitForTimeout(500);
167179

180+
// Record URL before submit to detect navigation
181+
const urlBeforeSubmit = page.url();
182+
168183
// Press Enter to submit
169184
await page.keyboard.press("Enter");
170185
console.log("[Perplexity Web Browser] DOM: typed message and pressed Enter");
171186

172-
// Wait for URL to change from home to a search result page
187+
// Wait for URL to change (new search creates a new URL)
173188
try {
174189
await page.waitForURL(
175-
(url) => url.pathname.startsWith("/search/") || url.pathname.startsWith("/c/"),
190+
(url) =>
191+
url.href !== urlBeforeSubmit &&
192+
(url.pathname.startsWith("/search/") || url.pathname.startsWith("/c/")),
176193
{ timeout: 15000 },
177194
);
178195
console.log("[Perplexity Web Browser] DOM: navigated to", page.url());

0 commit comments

Comments
 (0)