plans: S070 media pass (now playing priority, previews, media keys, PiP, controls row)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
b022d5db50
commit
41eb7d4c8f
13 changed files with 297 additions and 13 deletions
36
Plans/10 Hardening/S070-media-pass.md
Normal file
36
Plans/10 Hardening/S070-media-pass.md
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# S070 — Media pass: which player is "now playing", previews, media keys, PiP, controls
|
||||||
|
|
||||||
|
> Category 10 Hardening · Model: Opus · Effort: medium · Depends on: S068 · Size: M · Human: 🧑 user checks two videos + YouTube hover on their screen
|
||||||
|
> Files touched: src/actions.rs (media_tab ~2215, media commands), src/app.rs (update_media_now ~1282, crash/unresponsive → media cleared), src/inject.rs (MEDIA_JS `pick` ~151–190), src/tabs.rs (media fields), src/ui/menus.rs (media flyout ~1001–1160), src/ui/pages/newtab.rs (media card, if it shares the row), src/keys.rs (MediaPlayPause ~204), tests/smoke/pages/ (media test pages), tests/smoke/media-priority.txt (new)
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
User report (2026-11-18, screenshot of the media controls row):
|
||||||
|
1. **Priority**: with two videos in two windows/tabs, the one that started *first* keeps "the stage" (flyout, new tab card, Discord, media keys). Cause found by the orchestrator: `media_tab` returns the first audible tab in tab order (`tabs.iter().find(|t| t.audible())`). Rule (like Chromium/GNOME): the most recently **started or user-resumed** audible media wins; when it pauses, the previous one comes back only if still playing.
|
||||||
|
2. **Hover previews**: YouTube's hover autoplay (muted, short, no user gesture) counts as a whole video, and the controls sometimes stay stuck on the hovered video while another plays. In a page, `pick()` takes the first unpaused element. Rule: ignore muted / no-audio / tiny / preview elements (no user gesture, muted autoplay) unless nothing else exists; prefer the element the user played or the one with Media Session metadata; when the preview element is removed or paused, fall back at once (no stale state).
|
||||||
|
3. **Media keys and MPRIS**: Play/Pause, Next, Previous keys act on the chosen player (1); check what desktop media keys hit today (Nacre's key handler vs WebKit's per-web-process MPRIS players, S051) so the right one answers; note what WebKit allows.
|
||||||
|
4. **PiP**: PiP button and "Go to tab" act on the chosen player; entering PiP picks the main video, not a preview.
|
||||||
|
5. **After a crash or hang** (S068): a crashed/unresponsive tab's media state is cleared (no ghost "now playing").
|
||||||
|
6. **Controls row**: the buttons look uneven (mute, previous, next, PiP icons smaller and off-baseline next to the big pause button). One size for the side buttons, equal gaps, all centred on the big button's centre line, hover/press states like other icon buttons (app-taste rules); same in the new tab media card if it shares the code.
|
||||||
|
|
||||||
|
## Read
|
||||||
|
- `src/actions.rs` `media_tab`; `src/app.rs` `update_media_now`; `src/inject.rs` `MEDIA_JS`
|
||||||
|
- `src/ui/menus.rs` `media` and `media_art`; `src/keys.rs` media keys; S051/S060/S066 entries in `docs/PROGRESS.md`
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
- [ ] Pure rule for (1) in `media.rs` or `tabs.rs` (stamp `started_ms` when a tab's media goes paused → playing; choose max among audible) + unit test (two tabs, start order, pause/resume, preview ignored).
|
||||||
|
- [ ] (2) `MEDIA_JS`: element choice with the preview rules; send a clear state when the chosen element goes away; test page `pages/media-previews.html` (a main video + muted hover-style previews that start/stop/get removed).
|
||||||
|
- [ ] (3)+(4)+(5): keys and PiP use the chosen player; crashed/unresponsive tabs drop media state; check desktop media keys (playerctl on the run's bus) and write down what answers.
|
||||||
|
- [ ] (6) Controls row aligned (flyout + new tab card); before/after shots.
|
||||||
|
- [ ] `tests/smoke/media-priority.txt` (offline, `tests/smoke/pages` http server): two tabs, start order switches the chosen player, preview hover doesn't take it, removing the preview clears it; shots dark/light. Run it and `media-audio.txt` only.
|
||||||
|
- [ ] PROGRESS entry, INDEX line, tracker, commit `S070: …`, push.
|
||||||
|
- [ ] 🧑 (orchestrator asks the user) two videos in two windows + YouTube hover on their screen; note the answer.
|
||||||
|
|
||||||
|
## End criteria
|
||||||
|
- `cargo test` green; `media-priority.txt` and `media-audio.txt` exit 0; shots show the aligned row.
|
||||||
|
|
||||||
|
## Pitfalls
|
||||||
|
- Don't fight the page: never pause or mute a page's own previews; only choose what Nacre shows/controls.
|
||||||
|
- The S068 deadlock involves media elements starting/stopping: don't add JS that polls media elements fast; listen to events.
|
||||||
|
|
||||||
|
## Handoff (→ PROGRESS.md)
|
||||||
|
The priority rule, the preview rule, what media keys hit.
|
||||||
|
|
@ -20,10 +20,11 @@ Dropped with Servo (D-032): S011, S029, S030, S032, S033, S037, S038.
|
||||||
- [x] [S065 — Custom download manager by name and port](09%20Fix%20round/S065-custom-manager-port.md) · Sonnet high
|
- [x] [S065 — Custom download manager by name and port](09%20Fix%20round/S065-custom-manager-port.md) · Sonnet high
|
||||||
- [x] [S066 — UI alignment pass (/unslop)](09%20Fix%20round/S066-ui-alignment.md) · Opus medium · 🧑
|
- [x] [S066 — UI alignment pass (/unslop)](09%20Fix%20round/S066-ui-alignment.md) · Opus medium · 🧑
|
||||||
|
|
||||||
## 10 Hardening (after 09; one at a time)
|
## 10 Hardening (after 09; one at a time: S068, S067, S069, S070)
|
||||||
- [ ] [S067 — Passwords ask for your account password](10%20Hardening/S067-os-password-gate.md) · Opus high · 🧑
|
- [ ] [S067 — Passwords ask for your account password](10%20Hardening/S067-os-password-gate.md) · Opus high · 🧑
|
||||||
- [ ] [S068 — "Page isn't responding" and crash pages that show](10%20Hardening/S068-page-unresponsive.md) · Opus medium
|
- [ ] [S068 — "Page isn't responding" and crash pages that show](10%20Hardening/S068-page-unresponsive.md) · Opus medium
|
||||||
- [ ] [S069 — Keep VRAM use small](10%20Hardening/S069-vram.md) · Opus medium
|
- [ ] [S069 — Keep VRAM use small](10%20Hardening/S069-vram.md) · Opus medium
|
||||||
|
- [ ] [S070 — Media pass: now playing priority, previews, media keys, PiP, controls](10%20Hardening/S070-media-pass.md) · Opus medium · 🧑
|
||||||
|
|
||||||
## 02 Verify / 03 Gaps (after 08; reviews need the user)
|
## 02 Verify / 03 Gaps (after 08; reviews need the user)
|
||||||
- [ ] [S010 — Phase 2 review with the user](02%20Verify/S010-phase2-review.md) · Sonnet medium · 🧑
|
- [ ] [S010 — Phase 2 review with the user](02%20Verify/S010-phase2-review.md) · Sonnet medium · 🧑
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,12 @@ pub enum Command {
|
||||||
WindowDrag,
|
WindowDrag,
|
||||||
FocusPage,
|
FocusPage,
|
||||||
CrashReload,
|
CrashReload,
|
||||||
|
/// "This page isn't responding" → Wait: the bar goes away and comes back if the page still hasn't answered after
|
||||||
|
/// another `ui::dialogs::HANG_AFTER`.
|
||||||
|
HangWait(u64),
|
||||||
|
/// "This page isn't responding" → Reload page: kill its web process (every tab sharing it shows the crash page),
|
||||||
|
/// then load the page again.
|
||||||
|
HangReload(u64),
|
||||||
Quit,
|
Quit,
|
||||||
RestartBrowser,
|
RestartBrowser,
|
||||||
Toast(String),
|
Toast(String),
|
||||||
|
|
@ -867,6 +873,25 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Command::HangWait(tab_id) => {
|
||||||
|
if let Some((w, i)) = self.find_tab(tab_id) {
|
||||||
|
let tab = &mut self.windows.get_mut(&w).expect("found").tabs[i];
|
||||||
|
if tab.unresponsive.is_some() {
|
||||||
|
tab.unresponsive = Some(std::time::Instant::now());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Command::HangReload(tab_id) => {
|
||||||
|
if let Some((w, i)) = self.find_tab(tab_id) {
|
||||||
|
let tab = &mut self.windows.get_mut(&w).expect("found").tabs[i];
|
||||||
|
tab.unresponsive = None;
|
||||||
|
if let Some(web) = &tab.web {
|
||||||
|
eprintln!("tab {tab_id}: Reload page, its web process is killed");
|
||||||
|
web.webview.terminate();
|
||||||
|
web.webview.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
Command::Quit => self.quit(),
|
Command::Quit => self.quit(),
|
||||||
Command::RestartBrowser => {
|
Command::RestartBrowser => {
|
||||||
self.quit_now();
|
self.quit_now();
|
||||||
|
|
|
||||||
65
src/app.rs
65
src/app.rs
|
|
@ -608,6 +608,50 @@ impl App {
|
||||||
self.windows.get_mut(&w)?.tabs.get_mut(i)
|
self.windows.get_mut(&w)?.tabs.get_mut(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// WebKit's `is-web-process-responsive` changed, or (`answered`) a script sent to a page came back.
|
||||||
|
fn on_responsive(&mut self, id: ViewId, responsive: bool, answered: bool) {
|
||||||
|
let Some((w, i)) = self.find_webview(id) else { return };
|
||||||
|
let shown = self.windows[&w].active == i;
|
||||||
|
let tab = &mut self.windows.get_mut(&w).expect("found").tabs[i];
|
||||||
|
if responsive && !answered && !shown && tab.unresponsive.is_some() {
|
||||||
|
// WebKit calls a page responsive once its tab is hidden, busy or not: a script that comes back tells. A
|
||||||
|
// page still busy answers when it is done.
|
||||||
|
if let Some(web) = &tab.web {
|
||||||
|
let jobs = self.jobs_tx.clone();
|
||||||
|
web.webview.evaluate_javascript("0", move |_| {
|
||||||
|
let _ = jobs.send(Box::new(move |app: &mut App| app.on_responsive(id, true, true)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let url = tab.url.clone();
|
||||||
|
let line = match (responsive, tab.unresponsive) {
|
||||||
|
(false, None) => {
|
||||||
|
tab.unresponsive = Some(Instant::now());
|
||||||
|
format!("not responding {url}")
|
||||||
|
},
|
||||||
|
(true, Some(since)) => {
|
||||||
|
tab.unresponsive = None;
|
||||||
|
format!("responding again {url} after {:.1} s", since.elapsed().as_secs_f32())
|
||||||
|
},
|
||||||
|
_ => return,
|
||||||
|
};
|
||||||
|
eprintln!("{line}");
|
||||||
|
self.page_log(&line);
|
||||||
|
self.redraw(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A line in `pages.log` (crashes, pages that stopped answering), with the time; none in incognito.
|
||||||
|
fn page_log(&self, text: &str) {
|
||||||
|
if self.shared.incognito {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
use std::io::Write as _;
|
||||||
|
if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(self.shared.paths.crash_log()) {
|
||||||
|
let _ = writeln!(f, "{} {text}", util::format_stamp(util::now()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn redraw(&mut self, window: WindowId) {
|
pub fn redraw(&mut self, window: WindowId) {
|
||||||
if let Some(w) = self.windows.get(&window) {
|
if let Some(w) = self.windows.get(&window) {
|
||||||
w.redraw();
|
w.redraw();
|
||||||
|
|
@ -727,21 +771,27 @@ impl App {
|
||||||
},
|
},
|
||||||
Event::Crashed(id, reason) => {
|
Event::Crashed(id, reason) => {
|
||||||
let url = self.tab_mut(id).map(|t| t.url.clone()).unwrap_or_default();
|
let url = self.tab_mut(id).map(|t| t.url.clone()).unwrap_or_default();
|
||||||
if !self.shared.incognito {
|
self.page_log(&format!("crash {url}: {reason}"));
|
||||||
let line = format!("{} crash {url}: {reason}\n", util::format_stamp(util::now()));
|
let mut pip = None;
|
||||||
use std::io::Write as _;
|
|
||||||
if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(self.shared.paths.crash_log()) {
|
|
||||||
let _ = f.write_all(line.as_bytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(tab) = self.tab_mut(id) {
|
if let Some(tab) = self.tab_mut(id) {
|
||||||
tab.crashed = Some(reason);
|
tab.crashed = Some(reason);
|
||||||
|
tab.unresponsive = None;
|
||||||
tab.load_status = None;
|
tab.load_status = None;
|
||||||
|
// A dead page plays nothing.
|
||||||
|
tab.playing_audio = false;
|
||||||
|
tab.media = None;
|
||||||
|
pip = tab.pip_size.map(|_| tab.id);
|
||||||
}
|
}
|
||||||
if let Some((w, _)) = self.find_webview(id) {
|
if let Some((w, _)) = self.find_webview(id) {
|
||||||
|
// A dead page in the picture-in-picture window shows nothing: the tab takes its view back and
|
||||||
|
// shows the crash page.
|
||||||
|
if let Some(tab_id) = pip {
|
||||||
|
self.run(Command::ClosePip(tab_id));
|
||||||
|
}
|
||||||
self.redraw(w);
|
self.redraw(w);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Event::Responsive(id, responsive) => self.on_responsive(id, responsive, false),
|
||||||
Event::Fullscreen(id, on) => {
|
Event::Fullscreen(id, on) => {
|
||||||
if let Some((w, i)) = self.find_webview(id)
|
if let Some((w, i)) = self.find_webview(id)
|
||||||
&& let Some(win) = self.windows.get_mut(&w)
|
&& let Some(win) = self.windows.get_mut(&w)
|
||||||
|
|
@ -1020,6 +1070,7 @@ impl App {
|
||||||
tab.url = String::new();
|
tab.url = String::new();
|
||||||
tab.title = String::new();
|
tab.title = String::new();
|
||||||
tab.opener = Some(opener);
|
tab.opener = Some(opener);
|
||||||
|
tab.process = self.windows[&w].tabs[i].process;
|
||||||
tab.load_status = Some(LoadState::Started);
|
tab.load_status = Some(LoadState::Started);
|
||||||
tab.web = Some(Web { webview: view });
|
tab.web = Some(Web { webview: view });
|
||||||
let win = self.windows.get_mut(&w).expect("found");
|
let win = self.windows.get_mut(&w).expect("found");
|
||||||
|
|
|
||||||
|
|
@ -689,6 +689,8 @@ impl Engine {
|
||||||
hub.push(Event::Crashed(id, why.to_owned()));
|
hub.push(Event::Crashed(id, why.to_owned()));
|
||||||
});
|
});
|
||||||
let hub = self.hub.clone();
|
let hub = self.hub.clone();
|
||||||
|
web.connect_is_web_process_responsive_notify(move |w| hub.push(Event::Responsive(id, w.is_web_process_responsive())));
|
||||||
|
let hub = self.hub.clone();
|
||||||
web.connect_enter_fullscreen(move |_| {
|
web.connect_enter_fullscreen(move |_| {
|
||||||
hub.push(Event::Fullscreen(id, true));
|
hub.push(Event::Fullscreen(id, true));
|
||||||
true
|
true
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,8 @@ pub enum Event {
|
||||||
Closed(ViewId),
|
Closed(ViewId),
|
||||||
/// The web process died (crash, memory limit).
|
/// The web process died (crash, memory limit).
|
||||||
Crashed(ViewId, String),
|
Crashed(ViewId, String),
|
||||||
|
/// WebKit's `is-web-process-responsive` changed (false: the page's process didn't answer in time).
|
||||||
|
Responsive(ViewId, bool),
|
||||||
Fullscreen(ViewId, bool),
|
Fullscreen(ViewId, bool),
|
||||||
/// A main-frame navigation waits for `NavigationRequest::allow`/`deny`.
|
/// A main-frame navigation waits for `NavigationRequest::allow`/`deny`.
|
||||||
Navigation(ViewId, NavigationRequest),
|
Navigation(ViewId, NavigationRequest),
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,11 @@ impl View {
|
||||||
self.web.stop_loading();
|
self.web.stop_loading();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Kills the page's web process (and so every view sharing it); each gets `web-process-terminated`.
|
||||||
|
pub fn terminate(&self) {
|
||||||
|
self.web.terminate_web_process();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_loading(&self) -> bool {
|
pub fn is_loading(&self) -> bool {
|
||||||
self.web.is_loading()
|
self.web.is_loading()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@
|
||||||
//! do <action> a shortcut action by its settings key, e.g. `do new_tab`
|
//! do <action> a shortcut action by its settings key, e.g. `do new_tab`
|
||||||
//! cmd <name> [arg] back, forward, reload, bookmark, install_app, pip, exitpip, free_memory, ping_managers,
|
//! cmd <name> [arg] back, forward, reload, bookmark, install_app, pip, exitpip, free_memory, ping_managers,
|
||||||
//! update_lists, check_updates, close_tab, select <n>, zoom <step>,
|
//! update_lists, check_updates, close_tab, select <n>, zoom <step>,
|
||||||
|
//! hang_wait, hang_reload (the "isn't responding" bar's buttons), kill_page [n] (the n-th
|
||||||
|
//! tab's web process dies; default the active tab),
|
||||||
//! find <text>, download <url>, pause_download|resume_download|cancel_download [id] (newest),
|
//! find <text>, download <url>, pause_download|resume_download|cancel_download [id] (newest),
|
||||||
//! import <n> (bookmarks, history, settings from the n-th found browser profile),
|
//! import <n> (bookmarks, history, settings from the n-th found browser profile),
|
||||||
//! install_script <url> (a .user.js / .user.css), open_app [id] (default: the first installed app),
|
//! install_script <url> (a .user.js / .user.css), open_app [id] (default: the first installed app),
|
||||||
|
|
@ -454,6 +456,18 @@ impl App {
|
||||||
let tab = self.windows.get(&window).and_then(|w| w.tab()).map(|t| t.id).unwrap_or(0);
|
let tab = self.windows.get(&window).and_then(|w| w.tab()).map(|t| t.id).unwrap_or(0);
|
||||||
let page = self.windows.get(&window).and_then(|w| w.tab()).map(|t| t.url.clone()).unwrap_or_default();
|
let page = self.windows.get(&window).and_then(|w| w.tab()).map(|t| t.url.clone()).unwrap_or_default();
|
||||||
let newest = self.shared.downloads.borrow().items.first().map(|d| d.id).unwrap_or(1);
|
let newest = self.shared.downloads.borrow().items.first().map(|d| d.id).unwrap_or(1);
|
||||||
|
if name == "kill_page" {
|
||||||
|
// The web process of the n-th tab (default: the active one) dies, as on a crash.
|
||||||
|
let view = self.windows.get(&window).and_then(|w| match arg.parse::<usize>() {
|
||||||
|
Ok(n) => w.tabs.get(n),
|
||||||
|
Err(_) => w.tab(),
|
||||||
|
});
|
||||||
|
match view.and_then(|t| t.web.as_ref()) {
|
||||||
|
Some(web) => web.webview.terminate(),
|
||||||
|
None => self.selftest_log("kill_page: no web page"),
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
let command = match name {
|
let command = match name {
|
||||||
"back" => Command::Back,
|
"back" => Command::Back,
|
||||||
"forward" => Command::Forward,
|
"forward" => Command::Forward,
|
||||||
|
|
@ -463,6 +477,8 @@ impl App {
|
||||||
"pip" => Command::EnterPip,
|
"pip" => Command::EnterPip,
|
||||||
"exitpip" => Command::ClosePip(tab),
|
"exitpip" => Command::ClosePip(tab),
|
||||||
"free_memory" => Command::FreeMemory,
|
"free_memory" => Command::FreeMemory,
|
||||||
|
"hang_wait" => Command::HangWait(tab),
|
||||||
|
"hang_reload" => Command::HangReload(tab),
|
||||||
"ping_managers" => Command::PingManagers,
|
"ping_managers" => Command::PingManagers,
|
||||||
"update_lists" => Command::UpdateFilterLists,
|
"update_lists" => Command::UpdateFilterLists,
|
||||||
"check_updates" => Command::CheckUpdates,
|
"check_updates" => Command::CheckUpdates,
|
||||||
|
|
@ -898,7 +914,7 @@ impl App {
|
||||||
"active": i == w.active, "url": t.shown_url(), "title": t.display_title(), "loading": t.loading(),
|
"active": i == w.active, "url": t.shown_url(), "title": t.display_title(), "loading": t.loading(),
|
||||||
"load_status": format!("{:?}", t.load_status), "has_web": t.web.is_some(), "frozen": t.frozen, "blocked": t.blocked,
|
"load_status": format!("{:?}", t.load_status), "has_web": t.web.is_some(), "frozen": t.frozen, "blocked": t.blocked,
|
||||||
"hidden_elements": t.hidden_elements, "pinned": t.pinned, "muted": t.muted, "playing_audio": t.playing_audio, "audible": t.audible(), "zoom": t.zoom,
|
"hidden_elements": t.hidden_elements, "pinned": t.pinned, "muted": t.muted, "playing_audio": t.playing_audio, "audible": t.audible(), "zoom": t.zoom,
|
||||||
"favicon": t.favicon.is_some(), "crashed": t.crashed, "can_back": t.can_go_back(), "can_forward": t.can_go_forward(),
|
"favicon": t.favicon.is_some(), "crashed": t.crashed, "unresponsive": t.unresponsive.map(|s| s.elapsed().as_secs_f32()), "can_back": t.can_go_back(), "can_forward": t.can_go_forward(),
|
||||||
"history_len": t.back_forward.len(), "find": [t.find.index, t.find.count], "prompts": t.prompts.len(),
|
"history_len": t.back_forward.len(), "find": [t.find.index, t.find.count], "prompts": t.prompts.len(),
|
||||||
"dialog": t.dialog.is_some(), "closing": t.closing.is_some(), "page": t.page.as_ref().map(|p| p.url()), "history_state": t.history_state.is_some(), "media": t.media.as_ref().map(|(m, _)| serde_json::json!({"title": m.title, "paused": m.paused, "duration": m.duration, "position": m.position})),
|
"dialog": t.dialog.is_some(), "closing": t.closing.is_some(), "page": t.page.as_ref().map(|p| p.url()), "history_state": t.history_state.is_some(), "media": t.media.as_ref().map(|(m, _)| serde_json::json!({"title": m.title, "paused": m.paused, "duration": m.duration, "position": m.position})),
|
||||||
"theme_color": t.theme_color.map(crate::theme::to_hex), "favicon_colour": t.favicon_colour.map(crate::theme::to_hex), "site_colour": t.site_colour().map(crate::theme::to_hex), "pip": t.pip_size.is_some(),
|
"theme_color": t.theme_color.map(crate::theme::to_hex), "favicon_colour": t.favicon_colour.map(crate::theme::to_hex), "site_colour": t.site_colour().map(crate::theme::to_hex), "pip": t.pip_size.is_some(),
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,11 @@ pub struct Tab {
|
||||||
pub prompts: VecDeque<Prompt>,
|
pub prompts: VecDeque<Prompt>,
|
||||||
pub dialog: Option<Dialog>,
|
pub dialog: Option<Dialog>,
|
||||||
pub crashed: Option<String>,
|
pub crashed: Option<String>,
|
||||||
|
/// The page's web process stopped answering (WebKit `is-web-process-responsive`); since when.
|
||||||
|
pub unresponsive: Option<Instant>,
|
||||||
|
/// Tabs with the same value share a web process (a pop-up's related view shares its opener's): the tab id of the
|
||||||
|
/// first one.
|
||||||
|
pub process: u64,
|
||||||
/// The user closed the tab and its page runs `beforeunload` first (WebKit `try_close`); since when.
|
/// The user closed the tab and its page runs `beforeunload` first (WebKit `try_close`); since when.
|
||||||
pub closing: Option<std::time::Instant>,
|
pub closing: Option<std::time::Instant>,
|
||||||
/// HTTPS-only upgraded this load from this URL.
|
/// HTTPS-only upgraded this load from this URL.
|
||||||
|
|
@ -291,6 +296,8 @@ impl Tab {
|
||||||
dialog: None,
|
dialog: None,
|
||||||
closing: None,
|
closing: None,
|
||||||
crashed: None,
|
crashed: None,
|
||||||
|
unresponsive: None,
|
||||||
|
process: id,
|
||||||
upgraded_from: None,
|
upgraded_from: None,
|
||||||
redo: None,
|
redo: None,
|
||||||
cert_error: None,
|
cert_error: None,
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,52 @@ fn dialog_actions(ui: &mut Ui, contents: impl FnOnce(&mut Ui)) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// How long a page's web process may go without answering before the "isn't responding" bar shows.
|
||||||
|
pub const HANG_AFTER: std::time::Duration = std::time::Duration::from_secs(5);
|
||||||
|
|
||||||
|
/// "This page isn't responding" over the active tab's page: Wait, or Reload page (kills its web process). Clears
|
||||||
|
/// itself when the page answers again (`Event::Responsive`).
|
||||||
|
pub fn hang_bar(root: &mut Ui, f: &mut Frame) {
|
||||||
|
let Some(tab) = f.tab() else { return };
|
||||||
|
let Some(since) = tab.unresponsive.filter(|_| tab.page.is_none() && tab.crashed.is_none() && tab.pip_size.is_none()) else { return };
|
||||||
|
let waited = since.elapsed();
|
||||||
|
if waited < HANG_AFTER {
|
||||||
|
root.ctx().request_repaint_after(HANG_AFTER - waited);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let tab_id = tab.id;
|
||||||
|
// Pop-ups share their opener's web process: killing it reloads them too.
|
||||||
|
let others = f.tabs.iter().filter(|t| t.process == tab.process && t.id != tab_id && t.web.is_some()).count();
|
||||||
|
let text = match others {
|
||||||
|
0 => "This page isn't responding".to_owned(),
|
||||||
|
1 => "This page isn't responding. Reload page also stops 1 other tab that shares its process".to_owned(),
|
||||||
|
n => format!("This page isn't responding. Reload page also stops {n} other tabs that share its process"),
|
||||||
|
};
|
||||||
|
let p = f.palette();
|
||||||
|
let frame = egui::Frame::NONE.fill(p.surface_container_high).inner_margin(egui::Margin::symmetric(theme::GAP_L as i8, theme::GAP_S as i8));
|
||||||
|
egui::Panel::top("hang-bar").frame(frame).show(root, |ui| {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.spacing_mut().item_spacing.x = theme::GAP_S;
|
||||||
|
ui.set_min_height(theme::CONTROL);
|
||||||
|
let (rect, _) = ui.allocate_exact_size(Vec2::splat(theme::ICON_LARGE), Sense::hover());
|
||||||
|
icon(ui, rect.center(), icons::INFO, theme::ICON, false, p.primary);
|
||||||
|
ui.add_space(theme::GAP_XS);
|
||||||
|
let mut buttons = ui.new_child(egui::UiBuilder::new().max_rect(ui.max_rect()).layout(egui::Layout::right_to_left(egui::Align::Center)));
|
||||||
|
buttons.spacing_mut().item_spacing.x = theme::GAP_S;
|
||||||
|
if button(&mut buttons, ButtonKind::Filled, None, "Reload page").clicked() {
|
||||||
|
f.commands.push(Command::HangReload(tab_id));
|
||||||
|
}
|
||||||
|
if button(&mut buttons, ButtonKind::Tonal, None, "Wait").clicked() {
|
||||||
|
f.commands.push(Command::HangWait(tab_id));
|
||||||
|
}
|
||||||
|
let used = buttons.min_rect().width();
|
||||||
|
let width = (ui.available_width() - used - theme::GAP_L).max(80.0);
|
||||||
|
let galley = super::menus::one_line(ui, &text, theme::font(theme::BODY, Weight::Medium), p.on_surface, width);
|
||||||
|
ui.add(egui::Label::new(galley));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub fn prompt_bars(root: &mut Ui, f: &mut Frame) {
|
pub fn prompt_bars(root: &mut Ui, f: &mut Frame) {
|
||||||
let Some(tab) = f.tab() else { return };
|
let Some(tab) = f.tab() else { return };
|
||||||
let Some(prompt) = tab.prompts.front() else { return };
|
let Some(prompt) = tab.prompts.front() else { return };
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,7 @@ pub fn draw(root: &mut egui::Ui, f: &mut Frame) {
|
||||||
chrome::bookmarks_bar(root, f);
|
chrome::bookmarks_bar(root, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dialogs::hang_bar(root, f);
|
||||||
dialogs::prompt_bars(root, f);
|
dialogs::prompt_bars(root, f);
|
||||||
dialogs::find_bar(root, f);
|
dialogs::find_bar(root, f);
|
||||||
}
|
}
|
||||||
|
|
@ -272,14 +273,12 @@ fn page_contents(ui: &mut egui::Ui, f: &mut Frame) {
|
||||||
ui.vertical_centered(|ui| {
|
ui.vertical_centered(|ui| {
|
||||||
ui.add_space(rect.height() * 0.25);
|
ui.add_space(rect.height() * 0.25);
|
||||||
ui.heading("This page crashed");
|
ui.heading("This page crashed");
|
||||||
ui.label("Something on the page broke the engine. Reloading usually fixes it.");
|
// Why: a crash, the memory limit, or the process stopped (Reload page on a busy page that shares it).
|
||||||
|
ui.label(format!("{reason} Reloading usually fixes it."));
|
||||||
ui.add_space(8.0);
|
ui.add_space(8.0);
|
||||||
if ui.button("Reload").clicked() {
|
if ui.button("Reload").clicked() {
|
||||||
f.send(Command::CrashReload);
|
f.send(Command::CrashReload);
|
||||||
}
|
}
|
||||||
ui.collapsing("Details", |ui| {
|
|
||||||
ui.monospace(reason);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
72
tests/smoke/hang.txt
Normal file
72
tests/smoke/hang.txt
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
# Page isn't responding and crash pages (S068). Offline; hidden only (real clicks: tools/wl-input), SMOKE_SIZE=1280x900.
|
||||||
|
# A busy page: after HANG_AFTER (5 s) without an answer the bar shows (also when its tab comes back to the front), a
|
||||||
|
# second tab stays usable, Reload page kills the process and loads the page again; Wait hides the bar and it clears
|
||||||
|
# itself when the page answers. A killed web process shows the crash page: active tab, hidden tab, tab in picture in
|
||||||
|
# picture. Read the PNGs: hang-bar, hang-back, hang-wait, crash-active, crash-hidden, crash-pip.
|
||||||
|
wait 3
|
||||||
|
open @PAGES@/hang.html
|
||||||
|
waitload
|
||||||
|
locate #go
|
||||||
|
wait 0.5
|
||||||
|
click @
|
||||||
|
# The page can't take this click: WebKit waits for an answer and marks the process unresponsive.
|
||||||
|
wait 0.5
|
||||||
|
click 600 500
|
||||||
|
wait 9
|
||||||
|
expect /active/unresponsive > 5
|
||||||
|
shot hang-bar
|
||||||
|
newtab @PAGES@/hello.html
|
||||||
|
waitload
|
||||||
|
assert document.title === 'Smoke page'
|
||||||
|
expect /active/unresponsive null
|
||||||
|
shot hang-other
|
||||||
|
cmd select 0
|
||||||
|
wait 1
|
||||||
|
expect /active/unresponsive > 5
|
||||||
|
shot hang-back
|
||||||
|
cmd hang_reload
|
||||||
|
waitload
|
||||||
|
wait 1
|
||||||
|
expect /active/unresponsive null
|
||||||
|
expect /active/crashed null
|
||||||
|
assert document.getElementById('state').textContent === 'Idle'
|
||||||
|
# Wait: the bar goes; once the page is done it answers again and the tab is marked responsive.
|
||||||
|
locate #go
|
||||||
|
wait 0.5
|
||||||
|
click @
|
||||||
|
wait 0.5
|
||||||
|
click 600 500
|
||||||
|
wait 9
|
||||||
|
expect /active/unresponsive > 5
|
||||||
|
cmd hang_wait
|
||||||
|
wait 1
|
||||||
|
shot hang-wait
|
||||||
|
waitstatus 30 /active/unresponsive null
|
||||||
|
assert document.getElementById('state').textContent === 'Done'
|
||||||
|
# Crash pages.
|
||||||
|
cmd kill_page
|
||||||
|
wait 2
|
||||||
|
expect /active/crashed "The page was stopped."
|
||||||
|
shot crash-active
|
||||||
|
cmd kill_page 1
|
||||||
|
wait 2
|
||||||
|
expect /tabs/1/crashed "The page was stopped."
|
||||||
|
cmd select 1
|
||||||
|
wait 1
|
||||||
|
shot crash-hidden
|
||||||
|
open @PAGES@/video.html
|
||||||
|
waitload
|
||||||
|
expect /active/crashed null
|
||||||
|
waitfor 10 document.getElementById('v').currentTime > 0.5
|
||||||
|
cmd pip
|
||||||
|
wait 2
|
||||||
|
expect /active/pip true
|
||||||
|
cmd kill_page
|
||||||
|
wait 2
|
||||||
|
expect /windows 1
|
||||||
|
expect /active/pip false
|
||||||
|
expect /active/crashed "The page was stopped."
|
||||||
|
expect /active/audible false
|
||||||
|
shot crash-pip
|
||||||
|
status done
|
||||||
|
quit
|
||||||
22
tests/smoke/pages/hang.html
Normal file
22
tests/smoke/pages/hang.html
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head><meta charset="utf-8"><title>Hang page</title>
|
||||||
|
<style>
|
||||||
|
body { margin: 0; font: 24px sans-serif; background: #f4efe6; color: #222; }
|
||||||
|
h1 { margin: 40px; color: #1a5fb4; }
|
||||||
|
button { margin: 40px; font: inherit; padding: 12px 24px; }
|
||||||
|
</style></head>
|
||||||
|
<body>
|
||||||
|
<h1>Hang test</h1>
|
||||||
|
<!-- The button keeps the page's web process busy for 20 s: WebKit stops getting answers from it (S068). -->
|
||||||
|
<button id="go" onclick="hang(20000)">Busy for 20 s</button>
|
||||||
|
<p id="state" style="margin: 40px">Idle</p>
|
||||||
|
<script>
|
||||||
|
function hang(ms) {
|
||||||
|
const end = Date.now() + ms;
|
||||||
|
while (Date.now() < end) {}
|
||||||
|
document.getElementById('state').textContent = 'Done';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in a new issue