browser-assistant 2.9.39 → 2.9.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,6 +58,28 @@
58
58
  return null;
59
59
  }
60
60
  function descriptionText(description) {
61
+ // Read-only Ace examples contain hidden input/measurement text and
62
+ // line-number gutters. Only their rendered source lines are examples.
63
+ for (const editor of description.querySelectorAll('.ace_editor')) {
64
+ const lines = [...editor.querySelectorAll('.ace_text-layer .ace_line,.ace_line')];
65
+ if (lines.length) {
66
+ const pre = description.ownerDocument.createElement('pre');
67
+ pre.textContent = lines.map(line => line.textContent || '').join('\n');
68
+ editor.replaceWith(pre);
69
+ }
70
+ }
71
+ for (const node of description.querySelectorAll('.ace_text-input,.ace_gutter,.ace_gutter-layer,.ace_scrollbar,.ace_tooltip,[hidden]'))
72
+ node.remove();
73
+ const removeLayoutIndent = node => {
74
+ for (const child of [...node.childNodes]) {
75
+ if (child.nodeType === 3 && /^[\t \r\n]*[\r\n][\t \r\n]*$/.test(child.textContent || '')
76
+ && !child.parentElement?.closest('pre,code'))
77
+ child.remove();
78
+ else if (child.nodeType === 1)
79
+ removeLayoutIndent(child);
80
+ }
81
+ };
82
+ removeLayoutIndent(description);
61
83
  // A detached clone loses innerText's layout line breaks. Keep the line
62
84
  // structure of examples and the distinction between headings and prose.
63
85
  description.querySelectorAll('br').forEach(node => node.replaceWith('\n'));
@@ -68,7 +90,9 @@
68
90
  node.before('\n');
69
91
  node.after('\n');
70
92
  }
71
- return (description.textContent || '').trim();
93
+ // Do not trim spaces from the last sample: some pattern tasks
94
+ // explicitly require a space after every star, including the last one.
95
+ return (description.textContent || '').replace(/^\n+|\n+$/g, '');
72
96
  }
73
97
  const aliases = { python: 'python', python3: 'python', javascript: 'javascript', 'node.js': 'javascript', java: 'java', 'c++': 'cpp', cpp: 'cpp', c: 'c', 'c#': 'csharp', go: 'go', rust: 'rust', kotlin: 'kotlin', php: 'php', sql: 'sql' };
74
98
  function parseLanguage(label) {
@@ -125,6 +149,13 @@
125
149
  if (!language)
126
150
  return unavailable('CODE-LANGUAGE: Editor and description found, but the selected language is missing or ambiguous.');
127
151
  const description = region.cloneNode(true);
152
+ const originals = [...region.querySelectorAll('*')];
153
+ const copies = [...description.querySelectorAll('*')];
154
+ originals.forEach((node, index) => {
155
+ const style = doc.defaultView?.getComputedStyle?.(node);
156
+ if (node.hasAttribute('hidden') || style?.display === 'none' || style?.visibility === 'hidden')
157
+ copies[index].remove();
158
+ });
128
159
  for (const node of description.querySelectorAll('button,[role="tab"],script,style'))
129
160
  node.remove();
130
161
  for (const node of [...description.querySelectorAll('*')].reverse()) {
@@ -734,8 +734,11 @@ function mountJournalCountdown(signal) {
734
734
  diagnostic.hidden = false;
735
735
  const context = getAutomationContext();
736
736
  const authorized = context.mode === 'FULL';
737
- const currentQuestion = automation.batch?.title || (automation.running && automation.codingQuestionText)
738
- || (authorized ? getAuthorizedQuestion(context)?.text : '');
737
+ let currentQuestion = automation.batch?.title || (automation.running && automation.codingQuestionText);
738
+ if (!currentQuestion && authorized) {
739
+ const detected = getAuthorizedQuestion(context);
740
+ currentQuestion = detected?.title || detected?.text;
741
+ }
739
742
  const pageName = authorized ? context.target.id : window.location.hostname;
740
743
  const deferred = automation.deferredQuestions?.size ?? 0;
741
744
  if (status) {
@@ -1034,7 +1037,7 @@ function mountJournalCountdown(signal) {
1034
1037
  return null;
1035
1038
  }
1036
1039
  async function runCodingAutomation(question, runId, repairAttempt = 0, feedback = '', starterCode = null) {
1037
- automation.codingQuestionText = question.text;
1040
+ automation.codingQuestionText = question.title || 'Coding question';
1038
1041
  const active = () => automation.running && automation.runId === runId;
1039
1042
  const webProject = question.language === 'web';
1040
1043
  const read = () => safeSendMessage({ action: 'codingEditor', operation: webProject ? 'readProject' : 'read', selector: question.editorSelector });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Browser Assistant",
4
- "version": "2.9.39",
4
+ "version": "2.9.40",
5
5
  "description": "Scans webpages for MCQs and coding problems. Powered by Groq (cloud) and Ollama (local fallback).",
6
6
  "permissions": [
7
7
  "activeTab",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-assistant",
3
- "version": "2.9.39",
3
+ "version": "2.9.40",
4
4
  "description": "Chrome extension and local Python backend for exploring webpage questions and coding exercises",
5
5
  "license": "MIT",
6
6
  "repository": {
package/server/main.py CHANGED
@@ -195,7 +195,7 @@ async def lifespan(_app: FastAPI):
195
195
  client.close()
196
196
 
197
197
 
198
- app = FastAPI(title="Browser Assistant API", version="2.9.39", lifespan=lifespan)
198
+ app = FastAPI(title="Browser Assistant API", version="2.9.40", lifespan=lifespan)
199
199
  install_local_guards(app)
200
200
 
201
201
  @app.exception_handler(HTTPException)