papersearch 0.4.8 → 0.4.9

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.
@@ -261,11 +261,9 @@ class AccessMixin:
261
261
  return not getattr(getattr(self, "_item_result", None), "_pdf_retry_login", False)
262
262
 
263
263
  def _school_login_done(self) -> bool:
264
- """This item chose the school, went through an identity provider, or came
265
- back to the publisher from a login or chooser page, already."""
264
+ """This item reached its IdP; selecting a school is only an attempt."""
266
265
  result = getattr(self, "_item_result", None)
267
- return result is not None and (getattr(result, "_visited_idp", False) or getattr(result, "_login_round_trip", False)
268
- or any(e.get("state") in self._SCHOOL_CHOSEN for e in result.events))
266
+ return result is not None and (getattr(result, "_visited_idp", False) or getattr(result, "_login_round_trip", False))
269
267
 
270
268
  def _institution_pdf_entitlement_missing(self, page: Any, snapshot: SimpleNamespace | None = None) -> bool:
271
269
  """The article page denies access (access_rules.denial_evidence) to a
@@ -117,8 +117,10 @@ class DiagnosticsMixin:
117
117
  }.get(state)
118
118
  if state == "login_state" and getattr(result, "_login_attention", ""):
119
119
  report = ("等待在浏览器完成机构登录", "waiting_login")
120
- if state == "challenge_wait" and detail.startswith("manual "):
121
- report = ("等待人工安全验证", "waiting_verification")
120
+ if state == "challenge_manual_wait" or state == "challenge_wait" and detail.startswith("manual "):
121
+ report = (("等待人工安全验证", "waiting_verification")
122
+ if getattr(result, "_verification_attention", False)
123
+ else ("正在检查安全验证", "checking_access"))
122
124
  if state == "login_attempt_started" and detail in {"1/3", "2/3", "3/3"}:
123
125
  report = (f"机构登录:第 {detail[0]} 次尝试,共 3 次", "checking_access")
124
126
  if state == "login_observed":
@@ -538,12 +538,31 @@ class InstitutionMixin:
538
538
  except Exception as exc:
539
539
  if not _is_browser_error(exc):
540
540
  raise
541
- # Covered or moving: the script's click, as before.
541
+ # Custom listboxes can commit their option on mousedown (Cambridge
542
+ # WAYF), before blur closes the list. HTMLElement.click() alone
543
+ # leaves the option unselected even though no error is raised.
544
+ # This is only the already matched institution, never a challenge
545
+ # widget, credential field or another default choice.
546
+ # Omit MouseEventInit.view: Camoufox rejects the evaluation
547
+ # world's window as a Window, and the selection does not need it.
542
548
  try:
543
- page.evaluate("() => { const el = document.querySelector('[data-paper-search-entry]'); if (el) el.click(); }")
549
+ clicked = page.evaluate("""() => {
550
+ const el = document.querySelector('[data-paper-search-entry]');
551
+ if (!el || !el.getClientRects().length || el.closest('[disabled], [aria-disabled="true"]'))
552
+ return false;
553
+ const options = {bubbles:true, cancelable:true, button:0};
554
+ el.dispatchEvent(new MouseEvent('mousedown', {...options, buttons:1}));
555
+ el.dispatchEvent(new MouseEvent('mouseup', options));
556
+ el.click();
557
+ return true;
558
+ }""")
559
+ if clicked is not True:
560
+ return False
561
+ self._event(result, "institution_entry_dispatched", "mouse sequence after native click failure")
544
562
  except Exception as again:
545
563
  if not _is_browser_error(again):
546
564
  raise
565
+ self._event(result, "institution_select_error", str(again).split("\n", 1)[0][:200])
547
566
  return False
548
567
  self._event(result, "auto_institution_entry", f"{target['t'][:80]} @ {url}")
549
568
  self._event(result, "institution_selected", target["t"][:80] + (" (entityID)" if top == 4 else ""))
@@ -694,10 +713,11 @@ class InstitutionMixin:
694
713
  # The results list as soon as it shows the school (at most 5 s).
695
714
  if pump_until(page, lambda: self._click_unique_institution_entry(page, result, url), 5_000):
696
715
  return True
697
- self._event(result, "auto_institution_not_found", f"{query} @ {url}")
698
- # The publisher has no login route for the school: the login ends
699
- # here instead of waiting out the user's time (Neurology, 2026-11-01).
700
- result._institution_not_listed = True
716
+ # No successful selection within this short poll does not
717
+ # prove absence: results may arrive later, be ambiguous or
718
+ # temporarily unclickable. The login's existing page budget
719
+ # bounds later passes, which inspect the entries again.
720
+ self._event(result, "institution_list_not_ready", f"search selection pending @ {url}")
701
721
  return False
702
722
  except Exception as exc:
703
723
  # Kept, not dropped: this step once stalled 30 s without a trace.
@@ -215,6 +215,14 @@ class LoginMixin:
215
215
  a wait of more than 10 s records how it ended."""
216
216
  self._phase(result, "login")
217
217
  started, signed_in = time.time(), False
218
+
219
+ def observe_login_navigation(frame):
220
+ # A reused school session can cross the IdP and return between two
221
+ # polling passes. Observe only the main-frame host, never form data.
222
+ if frame == page.main_frame and self._is_idp_host(urlparse(str(frame.url)).netloc):
223
+ result._visited_idp = True
224
+
225
+ page.on("framenavigated", observe_login_navigation)
218
226
  try:
219
227
  from ..browser import watchdog
220
228
  # Human authentication has its own budget, not the automation's.
@@ -224,6 +232,7 @@ class LoginMixin:
224
232
  self._return_to_article_after_login(page, result)
225
233
  return signed_in
226
234
  finally:
235
+ page.remove_listener("framenavigated", observe_login_navigation)
227
236
  self._set_login_attention(result, "")
228
237
  last = next((e["state"] for e in reversed(result.events) if e["state"] != "wait"), "")
229
238
  self._note_wait(result, "school login", started, "signed in" if signed_in else (result.reason or last))
@@ -248,6 +257,8 @@ class LoginMixin:
248
257
  progress_reporter.report_stage("waiting_login", current=result.doi)
249
258
  else:
250
259
  progress_reporter.clear_attention(key)
260
+ if (progress_reporter.read_state() or {}).get("stage") == "waiting_login":
261
+ progress_reporter.report_stage("checking_access", current=result.doi)
251
262
  result._login_attention = message
252
263
 
253
264
  @contextmanager
@@ -355,6 +366,11 @@ class LoginMixin:
355
366
  f"{self._login_wait_page(page)} after {self.page_wait_sec:.0f} s")
356
367
  self._wait_ran_out(result)
357
368
  return False
369
+ # Navigation and auto-submit can finish during the preceding
370
+ # wait. Never publish the classification of the old document.
371
+ user_step = self._users_login_step(page)
372
+ wait.observe(page, user_step)
373
+ deadline = wait.deadline
358
374
  message = ""
359
375
  if user_step:
360
376
  kind = self._login_wait_page(page)
@@ -372,8 +388,9 @@ class LoginMixin:
372
388
  away_from_publisher = True
373
389
  elif here.hostname and away_from_publisher:
374
390
  away_from_publisher, returned = False, True
375
- result._login_round_trip = True
376
- self._event(result, "login_round_trip_returned", here.geturl()[:160])
391
+ if getattr(result, "_visited_idp", False):
392
+ result._login_round_trip = True
393
+ self._event(result, "login_round_trip_returned", here.geturl()[:160])
377
394
  if (on_publisher and self._is_success_article_url(here.geturl())
378
395
  and not self._is_auth_page(here.geturl()) and not self._challenge_shell(page)
379
396
  and (returned or time.time() - last_probe >= self.WAIT_PROBE_EVERY_SEC)
@@ -381,7 +398,7 @@ class LoginMixin:
381
398
  # Whoever signed in (this program or the user), the article page may
382
399
  # give its PDF although it still looks signed out to the rules (ASCE's
383
400
  # "GET ACCESS" after the login waited out five minutes, 2026-11-02): try it.
384
- after_login, returned, last_probe = returned, False, time.time()
401
+ after_login, returned, last_probe = returned and self._school_login_done(), False, time.time()
385
402
  if self._probe_pdf_while_waiting(page, result, after_login=after_login):
386
403
  return False # signed in, and the page still offers or denies the article
387
404
  elif (visited_idp and on_publisher and article_returns < 2
@@ -1234,16 +1251,28 @@ class LoginMixin:
1234
1251
  return now - outside_since >= self.page_wait_sec, outside_since
1235
1252
 
1236
1253
  def _users_login_step(self, page: Any) -> bool:
1237
- """The user's own step of the login, which may take the long wait
1238
- (``login_timeout_sec``): the school's login page (a password field, or the
1239
- school's identity provider), or a school chooser when no school is
1240
- configured or the user chooses by hand. Any other page off the publisher's
1241
- site is not: Atypon's iam.atypon.com hub, where AHA's login stopped on
1242
- 2026-11-03, was taken for the school's page and waited three minutes."""
1254
+ """Require a current credential/consent control, not just an IdP URL."""
1243
1255
  url = str(getattr(page, "url", "") or "")
1244
- if self._school_password_box(page, url) or self._is_idp_host(urlparse(url).netloc):
1256
+ if self._is_human_login_page(page):
1257
+ return True
1258
+ return (not self._is_idp_host(urlparse(url).netloc) and self._is_auth_page(url)
1259
+ and (not self.institution_query or bool(getattr(self, "_manual_school", False))))
1260
+
1261
+ def _idp_user_action(self, page: Any) -> bool:
1262
+ if not self._is_idp_host(urlparse(str(getattr(page, "url", "") or "")).netloc):
1263
+ return False
1264
+ if self._idp_confirmation(page):
1245
1265
  return True
1246
- return self._is_auth_page(url) and (not self.institution_query or bool(getattr(self, "_manual_school", False)))
1266
+ # Username-first and QR login pages may have no password box. Inspect
1267
+ # only visibility and labels; never collect input or QR contents.
1268
+ return page.evaluate("""() => {
1269
+ const visible = el => el.getClientRects().length > 0;
1270
+ const input = [...document.querySelectorAll('input')].some(el => visible(el)
1271
+ && !el.disabled && !el.readOnly && ['text','email','tel'].includes(el.type));
1272
+ const qr = [...document.querySelectorAll('img,canvas,[role="img"]')].some(el => visible(el)
1273
+ && /qr|二维码|扫码/i.test([el.id,el.className,el.getAttribute('alt'),el.getAttribute('aria-label')].join(' ')));
1274
+ return input || qr;
1275
+ }""") is True
1247
1276
 
1248
1277
  def _login_wait_page(self, page: Any) -> str:
1249
1278
  """Where a login that waited on the user ended (ADR 0012):
@@ -1259,21 +1288,17 @@ class LoginMixin:
1259
1288
  url = str(getattr(page, "url", "") or "")
1260
1289
  # The school's own page, by the same test as the long wait: a publisher's
1261
1290
  # SSO hub (iam.atypon.com) is no school login (2026-11-03).
1262
- if self._school_password_box(page, url) or self._is_idp_host(urlparse(url).netloc):
1291
+ if self._school_password_box(page, url) or self._idp_user_action(page):
1263
1292
  return "school_login"
1293
+ if self._is_idp_host(urlparse(url).netloc):
1294
+ return "authentication_redirect"
1264
1295
  if self._is_auth_page(url):
1265
1296
  return "institution_chooser" if self.institution_query else "school_choice"
1266
1297
  return "publisher" if self._on_publisher_host(url) else "other"
1267
1298
 
1268
1299
  def _is_human_login_page(self, page: Any) -> bool:
1269
- current_url = str(getattr(page, "url", "") or "")
1270
- host = (urlparse(current_url).netloc or "").lower()
1271
- if self.config.get("publisher_institution_federation") == "carsi":
1272
- if self._school_password_box(page, current_url):
1273
- return True
1274
- if not self._on_publisher_host(current_url):
1275
- return not self._is_federation_chooser(current_url)
1276
- return self._is_idp_host(host)
1300
+ url = str(getattr(page, "url", "") or "")
1301
+ return self._school_password_box(page, url) or self._idp_user_action(page)
1277
1302
 
1278
1303
  def _school_password_box(self, page: Any, url: str) -> bool:
1279
1304
  """A password or one-time-code field that is not a personal account's box on the publisher's site."""
@@ -1645,16 +1670,16 @@ class LoginMixin:
1645
1670
  try:
1646
1671
  button = (page.get_by_role("button", name="Next", exact=True) if selector == self._NEXT_BUTTON
1647
1672
  else page.locator(selector)).first
1648
- if button.is_visible(timeout=1_500):
1673
+ if button.is_visible(timeout=1_500) and button.is_enabled():
1649
1674
  try:
1650
1675
  text = (button.inner_text(timeout=1_000) or "").strip().lower()
1651
1676
  except Exception:
1652
1677
  text = ""
1653
1678
  if "continue reading" in text:
1654
1679
  continue
1655
- button.click(timeout=5_000, no_wait_after=True)
1656
- self._event(result, "institution_continue", selector)
1657
- return
1680
+ if self._click_control(page, button, result, "institution continue"):
1681
+ self._event(result, "institution_continue", selector)
1682
+ return
1658
1683
  except Exception as exc:
1659
1684
  if after_selection:
1660
1685
  # Our own selection's Continue failed: keep why (RSC's Next, 2026-11-01).
@@ -151,18 +151,21 @@ class UserWaitMixin:
151
151
  return True
152
152
  state, tab = "", None
153
153
  for candidate in pages:
154
+ if (urlparse(str(candidate.url or "")).hostname or "").lower() == suspect_host:
155
+ self._raise_on_publisher_access_blocked(candidate)
154
156
  try:
155
157
  if self._is_challenge_page(candidate):
156
158
  state, tab = "verification", candidate
157
159
  break
158
160
  if self._pdf_step_needs_login(candidate):
159
- state, tab = "login", candidate
161
+ state = "login" if candidate == page or self._users_login_step(candidate) else "unknown"
162
+ tab = candidate
160
163
  break
161
164
  except (watchdog.BrowserUnresponsive, UserMarkedNoEntitlement):
162
165
  raise
163
166
  except Exception:
164
167
  continue
165
- if not state and time.time() - started < self.SUSPECT_UNKNOWN_GRACE_SEC:
168
+ if not state and not automatic and shown not in {"verification", "login"}:
166
169
  for candidate in pages:
167
170
  try:
168
171
  if suspect_host and (urlparse(str(candidate.url or "")).hostname or "").lower() == suspect_host:
@@ -170,6 +173,10 @@ class UserWaitMixin:
170
173
  break
171
174
  except Exception:
172
175
  continue
176
+ if state == "unknown" and time.time() - started >= self.SUSPECT_UNKNOWN_GRACE_SEC:
177
+ captured["block_reason"] = "ip_blocked"
178
+ self._event(result, "ip_blocked_response", "PDF response remained blocked; no verification transition")
179
+ return False
173
180
  if not state:
174
181
  if shown or automatic:
175
182
  self._event(result, "challenge_resolved", f"{shown or 'verification'} page gone")
@@ -193,8 +200,12 @@ class UserWaitMixin:
193
200
  page.wait_for_timeout(min(1000, max(0, (deadline - time.time()) * 1000)))
194
201
  continue
195
202
  activity.automatic_for(0)
203
+ if state == "verification":
204
+ self._verification_attention(result, deadline)
196
205
  result._attention_page = tab
197
206
  if state != shown:
207
+ if state != "verification" and shown == "verification":
208
+ self._verification_attention(result, None)
198
209
  if state in ("verification", "login"):
199
210
  deadline = min(deadline, self._wait_deadline(result))
200
211
  self._event(result, {"verification": "challenge_manual_wait", "login": "pdf_step_login_wait",
@@ -236,6 +247,7 @@ class UserWaitMixin:
236
247
  self._event(result, "ip_blocked_response", f"{suspect} | no PDF after waiting ({shown or 'nothing shown'})")
237
248
  return False
238
249
  finally:
250
+ self._verification_attention(result, None)
239
251
  activity.automatic_for(0)
240
252
  result._attention_page = None
241
253
  if activity_owned:
@@ -365,55 +377,78 @@ class UserWaitMixin:
365
377
 
366
378
  def _automatic_challenge_step(self, page: Any, result: DownloadResult,
367
379
  attempt: dict[str, Any], deadline: float) -> bool:
368
- """Observe for an actionable widget within the existing verification wait.
380
+ """Count dispatched clicks only; reserve time for an observed user step.
369
381
 
370
- True means keep observing, never that verification passed. Each wait
371
- allows at most three interactions, including failed clicks, without a
372
- new budget. Observe for at least three seconds after each attempt.
382
+ An absent/loading widget stays automatic, including late arrivals. A
383
+ visible widget we cannot operate hands off within the existing budget.
373
384
  """
374
385
  now = time.time()
375
386
  if not attempt:
376
387
  attempt.update(started=now, attempts=0, retry_at=now + 2)
377
388
  self._event(result, "challenge_wait", "automatic verification check")
378
- # The spinner can run for more than 20 s before a checkbox appears.
379
- # Keep observing inside the caller's deadline; loading spends no click.
380
- # Reserve up to 2 s for manual handling without extending short waits.
381
- manual_reserve = min(2, max(0, deadline - attempt["started"]) * 0.2)
382
- # The enclosing page operation can already have spent time opening the
383
- # article. Hand off before that earlier bound, retaining the same user
384
- # wait deadline. Freeze it so pausing the operation cannot restart auto.
385
- if "automatic_end" not in attempt:
386
- remaining = watchdog.operation_remaining()
387
- bound = min(deadline, now + remaining) if remaining is not None else deadline
388
- attempt["automatic_end"] = bound - manual_reserve
389
- automatic_end = min(deadline - manual_reserve, attempt["automatic_end"])
389
+ remaining = watchdog.operation_remaining()
390
+ if "handoff_at" not in attempt:
391
+ # Default 60 s wait: look automatically for 30 s and leave 30 s for
392
+ # the user. Short waits retain half; the original deadline is fixed.
393
+ after = float(self.config.get("browser_stall_notify_after", 30))
394
+ budget = max(0, deadline - now)
395
+ if remaining is not None:
396
+ budget = min(budget, max(0, remaining))
397
+ attempt["handoff_at"] = now + min(after, budget / 2)
398
+ result._verification_notify_at = attempt["handoff_at"]
399
+ automatic_end = min(deadline, now + remaining) if remaining is not None else deadline
390
400
  activity = getattr(result, "_page_activity", None)
391
401
  if activity is not None:
392
- # The separate request watcher also checks idle time during these
393
- # RPCs. Use the frozen automatic bound; never renew the wait budget.
394
402
  activity.automatic_for(automatic_end - now)
395
- if now >= automatic_end or (attempt["attempts"] >= 3 and now >= attempt["retry_at"]):
396
- return False
397
403
  if challenge_interaction.needs_manual_verification(page):
398
- # We never operate this control. Waiting for it must not consume
399
- # the enclosing automation budget, even if the site clears itself.
400
- # The independent idle timer still decides when to remind the user.
401
404
  return False
405
+ if ((attempt["attempts"] >= 3 and now >= attempt["retry_at"])
406
+ or (attempt.get("unavailable") and now >= attempt["handoff_at"])):
407
+ return False
408
+ if now >= automatic_end:
409
+ # No observed user action: the caller ends at its original bound.
410
+ return True
402
411
  if now >= attempt["retry_at"] and attempt["attempts"] < 3:
403
- # Camoufox's native humanized move can take 1.5 s before mouse-down.
404
- # Leave time for that action, still inside the original wait budget.
412
+ reasons = []
405
413
  outcome = challenge_interaction.click_checkbox(
406
414
  page, timeout_ms=min(2500, max(1, int((automatic_end - now) * 1000))),
407
415
  checkpoint=lambda: self._check_user_decision(result, page),
416
+ observation=reasons.append,
408
417
  )
409
- if outcome != "absent":
418
+ reason = ", ".join(dict.fromkeys(reasons)) or outcome
419
+ if reason != attempt.get("last_observation"):
420
+ self._event(result, "challenge_observation", reason)
421
+ attempt["last_observation"] = reason
422
+ attempt["unavailable"] = outcome == "unavailable" and (not reasons or any(
423
+ value.startswith(("actionability_timeout", "unsupported_geometry_or_title", "multiple_controls"))
424
+ for value in reasons))
425
+ attempt["retry_at"] = time.time() + (3 if outcome != "absent" else 1)
426
+ if outcome == "clicked":
410
427
  attempt["attempts"] += 1
411
- attempt["retry_at"] = time.time() + 3
412
- if outcome == "clicked" and activity is not None:
428
+ if activity is not None:
413
429
  activity.progress(page)
414
430
  self._event(result, "challenge_interaction",
415
- f"checkbox {outcome}; attempt {attempt['attempts']}/3; awaiting verification")
416
- return time.time() < automatic_end
431
+ f"checkbox clicked; attempt {attempt['attempts']}/3; awaiting verification")
432
+ return True
433
+
434
+ def _verification_attention(self, result: DownloadResult, deadline: float | None) -> None:
435
+ from .. import progress_reporter
436
+ key = f"verification:{id(self)}:{result.doi}"
437
+ if deadline is None:
438
+ if getattr(result, "_verification_attention", False):
439
+ progress_reporter.clear_attention(key)
440
+ if (progress_reporter.read_state() or {}).get("stage") == "waiting_verification":
441
+ progress_reporter.report_stage("checking_access", current=result.doi)
442
+ result._verification_attention = False
443
+ elif time.time() < getattr(result, "_verification_notify_at", 0):
444
+ return
445
+ elif not getattr(result, "_verification_attention", False):
446
+ progress_reporter.set_attention(key, "自动验证尚未完成,请在浏览器中检查并完成验证",
447
+ current=result.doi, phase="安全验证", deadline=deadline)
448
+ progress_reporter.report_stage("waiting_verification", current=result.doi)
449
+ result._verification_attention = True
450
+ else:
451
+ progress_reporter.update_attention_deadline(key, deadline)
417
452
 
418
453
  def _wait_for_challenge(self, page: Any, result: DownloadResult, *, deadline: float | None = None) -> bool:
419
454
  """Wait while a verification page is up, until ``_wait_deadline``."""
@@ -445,6 +480,10 @@ class UserWaitMixin:
445
480
  if verification_wait is not None:
446
481
  verification_wait.observe(page, True)
447
482
  deadline = verification_wait.deadline
483
+ self._verification_attention(result, deadline)
484
+ from .. import progress_reporter
485
+ progress_reporter.update_attention_deadline(
486
+ f"verification:{id(self)}:{result.doi}", None if verification_wait.paused else deadline)
448
487
  if time.time() >= deadline:
449
488
  break
450
489
  result._attention_page = page
@@ -460,6 +499,7 @@ class UserWaitMixin:
460
499
  verification_deadline = deadline
461
500
  verification_wait = result._verification_wait = LoginWait(deadline, time.time)
462
501
  verification_wait.observe(page, True)
502
+ self._verification_attention(result, deadline)
463
503
  self._event(result, "challenge_manual_wait", "complete verification in visible browser")
464
504
  if not any(s["why"] == "waiting for the user: verification" for s in result.snapshots):
465
505
  self._snapshot(page, result, "waiting for the user: verification")
@@ -488,6 +528,7 @@ class UserWaitMixin:
488
528
  self._wait_ran_out(result)
489
529
  return passed
490
530
  finally:
531
+ self._verification_attention(result, None)
491
532
  activity.automatic_for(0)
492
533
  if verification_wait is not None:
493
534
  excluded = max(0, verification_wait.close() - verification_deadline)
@@ -1,4 +1,4 @@
1
- """Remind the user after an owned page makes no progress, without driving it.
1
+ """Track idle owned pages without treating missing progress as a user action.
2
2
 
3
3
  Main-document requests, navigation, a loaded document, a workflow step or
4
4
  received file bytes refresh the timer. An in-flight navigation gets only the
@@ -7,6 +7,7 @@ The request watcher can check the timer without making a browser RPC.
7
7
  """
8
8
  from __future__ import annotations
9
9
 
10
+ import logging
10
11
  import threading
11
12
  import time
12
13
  from contextlib import contextmanager
@@ -25,9 +26,8 @@ class PageActivity:
25
26
  self._clock = clock or time.monotonic
26
27
  self._last_progress = self._clock()
27
28
  self._lock = threading.RLock()
28
- self._key = f"page-stalled:{id(self)}:{doi}"
29
29
  self._doi = doi
30
- self._shown = False
30
+ self._reported = False
31
31
  self._transfers = 0
32
32
  self._automatic_until = 0.0
33
33
  self.closed = False
@@ -45,16 +45,14 @@ class PageActivity:
45
45
  self._clear()
46
46
 
47
47
  def _clear(self) -> None:
48
- if self._shown:
49
- progress_reporter.clear_attention(self._key)
50
- self._shown = False
48
+ self._reported = False
51
49
 
52
50
  def automatic_for(self, seconds: float) -> None:
53
- """Defer idle reminders until the caller's existing automatic deadline.
51
+ """Defer idle diagnostics until the caller's existing automatic deadline.
54
52
 
55
53
  This is a finite lease, not progress: polling must pass only the time
56
54
  remaining on the original bound. Zero releases it at manual handoff.
57
- The watcher can still remind if the browser call never returns.
55
+ The watcher can still log if the browser call never returns.
58
56
  """
59
57
  with self._lock:
60
58
  self._automatic_until = self._clock() + max(0.0, seconds)
@@ -66,19 +64,21 @@ class PageActivity:
66
64
  with self._lock:
67
65
  if self.closed:
68
66
  return
69
- if progress_reporter.has_attention(current=self._doi, excluding=self._key):
67
+ if progress_reporter.has_attention(current=self._doi):
70
68
  # School login and other explicit requests have priority. Start
71
69
  # a fresh quiet interval when they finish rather than duplicating them.
72
70
  self._last_progress = self._clock()
73
71
  self._clear()
74
- elif (not self._shown and not self._transfers
72
+ elif (not self._reported and not self._transfers
75
73
  and self._clock() >= self._automatic_until
76
74
  and not self._navigation_loading()
77
75
  and self._clock() - self._last_progress >= self.after):
78
- progress_reporter.set_attention(
79
- self._key, "页面持续没有进展,请查看浏览器,可能需要手动操作",
80
- current=self._doi, phase="需要人工处理")
81
- self._shown = True
76
+ # Silence is not evidence of a login or verification control.
77
+ # Keep a bounded diagnostic; only the workflow can request the
78
+ # user's attention after inspecting the current page.
79
+ logging.getLogger(__name__).info("page_idle: no observed progress for %.0f seconds",
80
+ self._clock() - self._last_progress)
81
+ self._reported = True
82
82
 
83
83
  def _navigation_loading(self) -> bool:
84
84
  pending = self._navigations.get(id(self.page))
@@ -156,7 +156,7 @@ class PageActivity:
156
156
  self.progress()
157
157
 
158
158
  def close(self) -> None:
159
- """Detach on the browser thread and clear any reminder before the next item."""
159
+ """Detach on the browser thread before the next item."""
160
160
  with self._lock:
161
161
  self.closed = True
162
162
  self._navigations.clear()