Web: Ctrl+Tab and Ctrl+Shift+Tab switch browser tabs again (#5227) (#5350)

* claim: #5227

* Web: leave Ctrl+Tab and Ctrl+Shift+Tab to the browser (#5227)

eframe cancels the default action of every Tab keydown on its canvas
(egui moves focus with Tab), so browsers that let a page cancel their
shortcuts, such as Vivaldi, could not switch tabs while SolidCraft had
the keyboard. A capture listener on the window now stops Ctrl+Tab and
Ctrl+Shift+Tab before they reach the canvas, without cancelling them,
so the browser acts on them as usual. Plain Tab and Shift+Tab still
move between the app's fields. Desktop builds are unchanged.

web-api-test checks it in headless Chrome: Ctrl+Tab and Ctrl+Shift+Tab
keydowns are not cancelled, Tab still is.

---------

Co-authored-by: MateuszSychXpl <151755914+MateuszSychXpl@users.noreply.github.com>
This commit is contained in:
Mateusz Sych
2026-10-23 13:42:27 +00:00
committed by GitHub
parent 867df396ea
commit 94279fe059
4 changed files with 61 additions and 1 deletions
+22
View File
@@ -87,13 +87,35 @@ pub fn run_api(site: &str) -> Result<(), String> {
let browser = Chrome::launch(&chrome, &work.0.join("profile"))?;
let mut cdp = browser.connect()?;
cdp.call("Emulation.setDeviceMetricsOverride", json!({"width": 1280, "height": 900, "deviceScaleFactor": 1, "mobile": false}))?;
// The page has the keyboard, as a tab the user is looking at does (for KEYS_TEST).
cdp.call("Emulation.setFocusEmulationEnabled", json!({"enabled": true}))?;
cdp.call("Page.navigate", json!({"url": format!("http://127.0.0.1:{}{PREFIX}?webgl", server.port)}))?;
wait_for(&mut cdp, "!!window.solidcraft && !document.getElementById('solidcraft_loading')", "the browser API is ready", |v| v == true)?;
let result = cdp.eval(API_TEST)?;
println!("web-api-test: {result}");
let keys = cdp.eval(KEYS_TEST)?;
println!("web-api-test: {keys}");
Ok(())
}
/// The browser's own tab switching keys reach it while the app has the keyboard (#5227): their
/// default action isn't cancelled, while Tab's is (the app moves between its fields with it).
const KEYS_TEST: &str = r#"(async () => {
const check = (condition, message) => { if (!condition) throw new Error(message); };
const canvas = document.getElementById('solidcraft_canvas');
canvas.focus();
canvas.dispatchEvent(new FocusEvent('focus'));
const cancelled = init => {
const e = new KeyboardEvent('keydown', {key: 'Tab', code: 'Tab', bubbles: true, cancelable: true, ...init});
canvas.dispatchEvent(e);
return e.defaultPrevented;
};
check(!cancelled({ctrlKey: true}), 'Ctrl+Tab is left to the browser');
check(!cancelled({ctrlKey: true, shiftKey: true}), 'Ctrl+Shift+Tab is left to the browser');
check(cancelled({}), 'the app takes Tab (it has the keyboard)');
return {ctrl_tab: 'browser', ctrl_shift_tab: 'browser', tab: 'app'};
})()"#;
const API_TEST: &str = r#"(async () => {
const app = window.solidcraft;
const check = (condition, message) => { if (!condition) throw new Error(message); };