# Site doctor (R1-04/R1-14, S006): heavy sites people sign in to or that guard themselves. Each one loads,
# gets a shot and a `js` line in selftest.log saying what the page has; `waitfor` fails the run when a page never
# gets that far. NEEDS INTERNET. Direct connections only: never a VPN, Tor or proxy (keep Nacre's VPN off).
# Nothing is submitted and no captcha is clicked: this checks that the pages and widgets work, not that a person
# can get past them. HTTP caching is tests/smoke/cache.txt (offline). Run with SMOKE_TIMEOUT=900 tools/smoke.sh tests/smoke/site-doctor.txt; read the PNGs.
wait 3
# DuckDuckGo: one search, then a result (a fresh profile, one search only, so its rate limit stays out of it).
open https://duckduckgo.com/
waitfor 60 !!document.querySelector("textarea[name=q], input[name=q]")
wait 1
locate textarea[name=q], input[name=q]
wait 1
click @
wait 0.5
pagetype webkit browser engine
wait 1
pagetype {enter}
waitfor 60 location.search.includes("q=webkit") && document.querySelectorAll("a[data-testid=result-title-a]").length > 0
wait 2
js JSON.stringify({ results: document.querySelectorAll("a[data-testid=result-title-a]").length, oops: document.body.innerText.includes("Oops") })
shot ddg-results
locate a[data-testid=result-title-a]
wait 1
click @
waitfor 60 location.hostname !== "duckduckgo.com" && document.readyState !== "loading"
wait 2
js location.href
shot ddg-result-opened
# Google sign-in: the page, its email field takes typing. Nothing is sent (no Next).
open https://accounts.google.com/
waitfor 60 !!document.querySelector("#identifierId")
wait 3
shot google-signin
locate #identifierId
wait 1
click @
wait 0.5
pagetype nacre.smoke.test
wait 1
js JSON.stringify({ url: location.href.slice(0, 80), field: document.querySelector("#identifierId").value, next: [...document.querySelectorAll("button")].map(b => b.innerText.trim()).filter(Boolean).slice(0, 5), text: document.body.innerText.slice(0, 200) })
shot google-signin-typed
# reCAPTCHA v2 demo: the widget's iframe loads and has a size (its checkbox is not clicked).
open https://www.google.com/recaptcha/api2/demo
waitfor 60 [...document.querySelectorAll("iframe[src*=recaptcha]")].some(f => f.getBoundingClientRect().width > 0)
wait 6
js JSON.stringify([...document.querySelectorAll("iframe")].map(f => ({ src: f.src.slice(0, 60), w: f.getBoundingClientRect().width, h: f.getBoundingClientRect().height })))
shot recaptcha
# hCaptcha demo.
open https://accounts.hcaptcha.com/demo
waitfor 60 [...document.querySelectorAll("iframe[src*=hcaptcha]")].some(f => f.getBoundingClientRect().width > 0)
wait 6
js JSON.stringify([...document.querySelectorAll("iframe")].map(f => ({ src: f.src.slice(0, 60), w: f.getBoundingClientRect().width, h: f.getBoundingClientRect().height })))
shot hcaptcha
# Cloudflare Turnstile demo (it may pass by itself: that is what Turnstile does for a normal browser). The widget
# lives in a shadow root, so the check looks at the API object, the container and the response field.
open https://demo.turnstile.workers.dev/
waitfor 60 document.readyState !== "loading"
wait 20
js JSON.stringify({ api: typeof turnstile, container: (document.querySelector(".cf-turnstile") || {}).outerHTML?.slice(0, 200), h: document.querySelector(".cf-turnstile")?.getBoundingClientRect().height, shadow: !!document.querySelector(".cf-turnstile div")?.shadowRoot, token: (document.querySelector("input[name=cf-turnstile-response]") || {}).value ? "set" : "empty", scripts: [...document.scripts].map(s => s.src.slice(0, 70)).filter(Boolean) })
shot turnstile
# Reddit: a subreddit, scroll.
open https://www.reddit.com/r/rust/
waitfor 90 document.readyState === "complete"
wait 4
js JSON.stringify({ title: document.title, posts: document.querySelectorAll("shreddit-post, article").length, blocked: /blocked|whoa there/i.test(document.body.innerText.slice(0, 2000)) })
shot reddit
pagescroll 400 300 1500
wait 2
js window.scrollY
shot reddit-scrolled
# GitHub: a repository, its README, a file.
open https://github.com/WebKit/WebKit
waitfor 90 document.readyState === "complete" && !!document.querySelector("article.markdown-body, [data-testid=readme], #readme")
wait 2
shot github-repo
pagescroll 400 300 1500
wait 2
shot github-readme
open https://github.com/WebKit/WebKit/blob/main/ReadMe.md
waitfor 90 document.readyState === "complete"
wait 3
js JSON.stringify({ title: document.title, code: !!document.querySelector("article.markdown-body, react-app, [data-testid=read-only-cursor-text-area]") })
shot github-file
status done
quit
