Skip to content

Commit ced39df

Browse files
committed
Update Perplexity content script to use new DOM selectors and improved model/option handling, and remove the deprecated Sonar model from the CHATBOTS constant
1 parent a48c850 commit ced39df

2 files changed

Lines changed: 22 additions & 18 deletions

File tree

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/perplexity.ts‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ export const perplexity: Chatbot = {
3131
const model = chat.model
3232
if (!model) return
3333

34-
const model_button = document
35-
.querySelector('button[data-testid="sources-switcher-button"]')
36-
?.closest('div')
37-
?.querySelector(':scope > div button') as HTMLButtonElement
34+
const model_button = document.querySelector(
35+
'input[multiple] + button + div button'
36+
) as HTMLButtonElement
3837
if (!model_button) {
3938
report_initialization_error({
4039
function_name: 'set_model',
@@ -55,23 +54,23 @@ export const perplexity: Chatbot = {
5554
model_button.click()
5655
await new Promise((r) => requestAnimationFrame(r))
5756

58-
const menu = document.querySelector(
57+
let dropdown = document.querySelector(
5958
'div[data-type="portal"] div[role="menu"]'
6059
)
61-
if (!menu) {
60+
if (!dropdown) {
6261
report_initialization_error({
6362
function_name: 'set_model',
64-
log_message: 'Model selector menu not found'
63+
log_message: 'Model selector dropdown not found'
6564
})
66-
model_button.click()
6765
return
6866
}
6967

70-
const menu_items = menu.querySelectorAll('div[role="menuitem"]')
68+
const menu_items = dropdown.querySelectorAll('div[role="menuitem"]')
7169
let found = false
7270
for (const item of Array.from(menu_items)) {
73-
if (item.textContent?.trim() == model_label_to_find) {
71+
if (item.textContent?.includes(model_label_to_find)) {
7472
;(item as HTMLElement).click()
73+
await new Promise((r) => requestAnimationFrame(r))
7574
found = true
7675
break
7776
}
@@ -91,7 +90,12 @@ export const perplexity: Chatbot = {
9190
'with-reasoning'
9291
)
9392

94-
const switch_button = menu.querySelector(
93+
// Reassign because the dropdown re-rendered
94+
dropdown = document.querySelector(
95+
'div[data-type="portal"] div[role="menu"]'
96+
)!
97+
98+
const switch_button = dropdown.querySelector(
9599
'button[role="switch"]'
96100
) as HTMLElement
97101

@@ -108,15 +112,14 @@ export const perplexity: Chatbot = {
108112
},
109113
set_options: async (chat) => {
110114
const options = chat.options
111-
if (!options) return
112115

113-
if (options.includes('search')) {
116+
if (options && options.includes('search')) {
114117
// Enabled by default
115118
return
116119
}
117120

118121
const switcher_button = document.querySelector(
119-
'button[data-testid="sources-switcher-button"]'
122+
'input[multiple] + button'
120123
) as HTMLButtonElement
121124
if (!switcher_button) {
122125
report_initialization_error({
@@ -126,11 +129,13 @@ export const perplexity: Chatbot = {
126129
return
127130
}
128131

129-
switcher_button.click()
132+
switcher_button.dispatchEvent(
133+
new PointerEvent('pointerdown', { bubbles: true })
134+
)
130135
await new Promise((r) => requestAnimationFrame(r))
131136

132137
const web_toggle = document.querySelector(
133-
'div[data-testid="source-toggle-web"]'
138+
'div[data-testid="sources-menu-suggested-sources"] > div button'
134139
) as HTMLElement
135140
if (web_toggle) {
136141
web_toggle.click()
@@ -214,7 +219,7 @@ export const perplexity: Chatbot = {
214219
'button[data-testid="stop-generating-response-button"]'
215220
),
216221
footer_selector:
217-
'.max-w-threadContentWidth > .relative > div > div > div > div > div + div > div',
222+
'.relative.font-sans + div > div.items-center:first-child',
218223
add_buttons
219224
})
220225
}

‎packages/shared/src/constants/chatbots.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ export const CHATBOTS = {
196196
search: 'Search'
197197
},
198198
models: {
199-
sonar: { label: 'Sonar', disabled_options: ['with-reasoning'] },
200199
'gpt-5.1': { label: 'GPT-5.1' },
201200
'claude-opus-4.5': { label: 'Claude Opus 4.5' },
202201
'gemini-3-pro': {

0 commit comments

Comments
 (0)