|
21 | 21 | chatgpt: { |
22 | 22 | turns: [ |
23 | 23 | "article[data-testid^='conversation-turn-']", |
| 24 | + "[data-testid='conversation-turn']", |
| 25 | + '[data-message-author-role]', |
24 | 26 | '[data-message-id]', |
25 | 27 | ], |
26 | 28 | turnRoleAttr: 'data-turn', |
@@ -556,10 +558,25 @@ function makePathEntry(turn) { |
556 | 558 | } |
557 | 559 |
|
558 | 560 | function readChatGPTTurns() { |
559 | | - const turns = [...document.querySelectorAll('article[data-testid^="conversation-turn-"]')]; |
| 561 | + let turns = [...document.querySelectorAll('article[data-testid^="conversation-turn-"]')]; |
| 562 | + |
| 563 | + if (!turns.length) { |
| 564 | + const fallbackSelectors = [ |
| 565 | + "[data-testid='conversation-turn']", |
| 566 | + '[data-message-author-role]', |
| 567 | + 'main article', |
| 568 | + ]; |
| 569 | + const candidates = dedupeElements(fallbackSelectors.flatMap(sel => [...document.querySelectorAll(sel)])) |
| 570 | + .filter(el => isReadableTurnCandidate(el, { minText: 2 })); |
| 571 | + turns = candidates |
| 572 | + .filter(el => !candidates.some(other => other !== el && other.contains(el))) |
| 573 | + .sort((a, b) => rectTop(a) - rectTop(b)); |
| 574 | + } |
| 575 | + |
560 | 576 | return turns.map((turn, idx) => { |
561 | | - const role = turn.getAttribute('data-turn') === 'user' ? 'user' : 'assistant'; |
562 | | - const msgDiv = turn.querySelector('[data-message-id]'); |
| 577 | + const roleAttr = turn.getAttribute('data-turn') || turn.getAttribute('data-message-author-role') || ''; |
| 578 | + const role = /^user$/i.test(roleAttr) ? 'user' : 'assistant'; |
| 579 | + const msgDiv = turn.matches('[data-message-id]') ? turn : turn.querySelector('[data-message-id]'); |
563 | 580 | const msgId = msgDiv?.getAttribute('data-message-id') || turn.getAttribute('data-turn-id') || null; |
564 | 581 | const nav = findChatGPTBranchNav(turn); |
565 | 582 | return { |
@@ -1007,17 +1024,28 @@ function makePathEntry(turn) { |
1007 | 1024 | return false; |
1008 | 1025 | } |
1009 | 1026 |
|
| 1027 | + function isLikelyChatConversationPage() { |
| 1028 | + try { |
| 1029 | + const path = new URL(location.href).pathname || ''; |
| 1030 | + return path.includes('/c/'); |
| 1031 | + } catch (_) { |
| 1032 | + return (location.pathname || '').includes('/c/'); |
| 1033 | + } |
| 1034 | + } |
| 1035 | + |
1010 | 1036 | function syncStateToPanel(force = false) { |
1011 | 1037 | const turns = serializeTurns(readRawTurns()); |
1012 | 1038 | if (!turns.length) { |
1013 | 1039 | if (pageSeemsLoading()) { |
1014 | 1040 | sendToPanel({ type: 'CONVERSATION_LOADING' }); |
1015 | 1041 | return; |
1016 | 1042 | } |
1017 | | - maybeReportBreakage('no_turns_detected', { |
1018 | | - phase: 'sync', |
1019 | | - force, |
1020 | | - }); |
| 1043 | + if (isLikelyChatConversationPage()) { |
| 1044 | + maybeReportBreakage('no_turns_detected', { |
| 1045 | + phase: 'sync', |
| 1046 | + force, |
| 1047 | + }); |
| 1048 | + } |
1021 | 1049 | sendToPanel({ type: 'CONVERSATION_LOADING' }); |
1022 | 1050 | return; |
1023 | 1051 | } |
|
0 commit comments