GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(desktop): browser toolbar with mobile and custom viewport sizes … · yusha/opencode@1cb0633

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • app
      • component-tests
        • browser-pane-restore.spec.ts
        • browser-pane.spec.ts
      • src/runtime/plugin
        • embeds.tsx
      • test-browser
        • browser-pane-model.test.ts
    • desktop/src
      • main/plugin
        • embeds.ts
        • host.ts
      • shared/ipc-rpc
        • plugins.ts
    • gui-plugins/src/browser
      • assets
        • viewport-device-chevron.svg
        • viewport-rotate.svg
      • bar.css
      • chromium.ts
      • comment.css
      • connection.test.ts
      • connection.ts
      • i18n
        • en.ts
      • ipc.ts
      • keys.test.ts
      • keys.ts
      • main.ts
      • mobile-emulation.ts
      • model.ts
      • pane.ts
      • panel.fixture.tsx
      • panel.tsx
      • renderer.tsx
      • viewport-controls-machine.test.ts
      • viewport-controls-machine.ts
      • viewport-controls.tsx
      • viewport-handles.tsx
      • viewport-layout.ts
      • viewport-native.test.ts
      • viewport-native.ts
      • viewport-preset-menu.tsx
      • viewport-presets.ts
      • viewport-toolbar-machine.test.ts
      • viewport-toolbar-machine.ts
    • plugin/src/gui
      • host.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/app/component-tests/browser-pane-restore.spec.ts‎

Copy file name to clipboardExpand all lines: packages/app/component-tests/browser-pane-restore.spec.ts
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ story("toggles the element picker from the shortcut only inside the browser pane
279279
)
280280
})
281281

282-
story("keeps in-page shortcuts like ⌘K in the page while forwarding ⌘⇧R and ⌘W to the pane", async ({ page }) => {
282+
story("keeps in-page shortcuts in the editor and forwards toolbar, review and close shortcuts", async ({ page }) => {
283283
const root = page.getByTestId("browser-region-fixture")
284284
const mac = await page.evaluate(() => /Mac|iPhone|iPad|iPod/.test(navigator.platform))
285285
const mod = mac ? "Meta" : "Control"
@@ -299,6 +299,23 @@ story("keeps in-page shortcuts like ⌘K in the page while forwarding ⌘⇧R an
299299
await editor.press(`${mod}+k`)
300300
await expect(editor).toHaveValue("handled:k")
301301

302+
const toggle = root.getByRole("button", { name: "Toggle browser toolbar", exact: true })
303+
await editor.press(`${mod}+Shift+m`)
304+
await expect(toggle).toHaveAttribute("aria-expanded", "true")
305+
await expect(toggle).toBeFocused()
306+
await root.getByRole("button", { name: "Device preset", exact: true }).press("ArrowDown")
307+
await page.getByRole("menuitem", { name: "More devices", exact: true }).press("ArrowRight")
308+
await expect(page.getByRole("menuitemradio", { name: "iPhone SE", exact: true })).toBeFocused()
309+
await page.keyboard.press(`${mod}+Shift+m`)
310+
await expect(toggle).toHaveAttribute("aria-expanded", "false")
311+
await expect(toggle).toBeFocused()
312+
await expect(toggle).toHaveCSS("outline-style", "solid")
313+
await toggle.click()
314+
await expect(toggle).toBeFocused()
315+
await expect(toggle).toHaveCSS("outline-style", "none")
316+
await page.keyboard.press(`${mod}+Shift+m`)
317+
await expect(toggle).toHaveCSS("outline-style", "solid")
318+
302319
// Shell shortcuts like ⌘⇧R and pane-scoped ⌘W are claimed before the page sees them.
303320
await editor.press(`${mod}+Shift+r`)
304321
await expect(root.getByTestId("review-toggles")).toHaveText("1")
Collapse file

‎packages/app/component-tests/browser-pane.spec.ts‎

Copy file name to clipboardExpand all lines: packages/app/component-tests/browser-pane.spec.ts
+262-3Lines changed: 262 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect, sourceURL, story } from "../../stories/playwright/story"
2+
import type { Locator, Page } from "@playwright/test"
23

34
const source = (path: string) => sourceURL(new URL(path, import.meta.url))
45

@@ -876,13 +877,18 @@ story("lists recent pages on a blank tab and opens one", async ({ page }) => {
876877
await expect(address).toHaveValue("http://localhost:5173/settings")
877878
})
878879

879-
story("adds the whole page to the session and keeps the draft when the button is pressed again", async ({ page }) => {
880-
const root = page.getByTestId("browser-pane-fixture")
880+
story("keeps a page note editable beside a tiny viewport and attaches it to the session", async ({ page }) => {
881+
const { root, viewport, width, height } = viewportControls(page)
882+
await viewport.click()
883+
await width.fill("8")
884+
await height.fill("8")
885+
await expectSize(root.getByTestId("native-Alpha"), 8, 8)
881886
const field = root.locator('[data-component="browser-address"]')
882887
const add = root.getByRole("button", { name: "Add page to session", exact: true })
883888
await field.hover()
884889
await add.click()
885890
const editor = root.locator('[data-slot="browser-comment-editor"] textarea')
891+
await editor.click()
886892
await editor.fill("Check the header layout")
887893
await field.hover()
888894
await add.click()
@@ -913,12 +919,51 @@ story("says a failed cookie read failed and reads again on retry", async ({ page
913919
await expect(site.getByRole("button", { name: "Clear", exact: true })).toBeEnabled()
914920
})
915921

916-
story("zooms the page from the browser options in view and keeps its zoom in the address field", async ({ page }) => {
922+
function viewportControls(page: Page) {
917923
const root = page.getByTestId("browser-pane-fixture")
924+
925+
const controls = root.getByRole("region", { name: "Viewport", exact: true })
926+
927+
return {
928+
root,
929+
controls,
930+
viewport: root.getByRole("button", { name: "Toggle browser toolbar", exact: true }),
931+
preset: controls.getByRole("button", { name: "Device preset", exact: true }),
932+
option: (name: string) => page.getByRole("menuitemradio", { name, exact: true }),
933+
moreDevices: page.getByRole("menuitem", { name: "More devices", exact: true }),
934+
width: controls.getByLabel("Viewport width in CSS pixels", { exact: true }),
935+
height: controls.getByLabel("Viewport height in CSS pixels", { exact: true }),
936+
scale: controls.getByRole("button", { name: "Preview scale", exact: true }),
937+
rotate: controls.getByRole("button", { name: "Rotate viewport", exact: true }),
938+
}
939+
}
940+
941+
function resizePane(root: Locator, width: number) {
942+
return root.locator("#browser-panel").evaluate((pane, width) => {
943+
if (!pane.parentElement) throw new Error("Missing pane container")
944+
pane.parentElement.style.width = `${width}px`
945+
}, width)
946+
}
947+
948+
async function expectSize(native: Locator, width: number, height: number) {
949+
await expect(native).toHaveAttribute("data-width", String(width))
950+
await expect(native).toHaveAttribute("data-height", String(height))
951+
}
952+
953+
story("zooms the page from the browser options in view and keeps its zoom in the address field", async ({ page }) => {
954+
const { root, controls, viewport, preset, option, scale } = viewportControls(page)
955+
await viewport.click()
956+
await preset.click()
957+
await option("Samsung Galaxy S26").click()
958+
await expect(preset).toHaveText("Samsung Galaxy S26")
918959
const options = root.getByRole("button", { name: "Browser options", exact: true })
919960
await options.click()
920961
await page.getByRole("menuitem", { name: /^Zoom in/ }).click()
921962
await expect(root.getByText("Zoom: 110", { exact: true })).toBeVisible()
963+
await expect(controls.getByRole("status")).toContainText("The page is using the pane size because page zoom changed.")
964+
await expect(preset).toBeDisabled()
965+
await expect(preset).toHaveText("Responsive")
966+
await expect(scale).toBeDisabled()
922967
// The menu covered the page with a still; it closes so the zoomed page shows at once.
923968
await expect(page.getByRole("menu")).toBeHidden()
924969
await expect(root.getByTestId("native-Alpha")).toHaveAttribute("data-visible", "true")
@@ -928,4 +973,218 @@ story("zooms the page from the browser options in view and keeps its zoom in the
928973
await zoom.click()
929974
await expect(root.getByText("Zoom: 100", { exact: true })).toBeVisible()
930975
await expect(zoom).toBeHidden()
976+
await expect(preset).toBeEnabled()
977+
})
978+
979+
story("restores the full pane when the toolbar closes and keeps the selected device on reopen", async ({ page }) => {
980+
const { root, controls, viewport, preset, option, moreDevices, width, height } = viewportControls(page)
981+
982+
const native = root.getByTestId("native-Alpha")
983+
984+
const fullWidth = await native.getAttribute("data-width")
985+
986+
const fullHeight = await native.getAttribute("data-height")
987+
988+
if (!fullWidth || !fullHeight) throw new Error("Missing native page bounds")
989+
990+
await viewport.click()
991+
await preset.press("ArrowDown")
992+
const menu = page.getByRole("menu")
993+
await expect(option("Responsive")).toBeChecked()
994+
await expect(menu.getByRole("menuitemradio")).toHaveText([
995+
"Responsive",
996+
"Samsung Galaxy S26",
997+
"iPhone 18 Pro",
998+
"iPad / iPad Air 11″",
999+
"Laptop",
1000+
"Desktop",
1001+
])
1002+
await page.keyboard.press("End")
1003+
await expect(moreDevices).toBeFocused()
1004+
await page.keyboard.press("ArrowRight")
1005+
const mini = option("iPad mini")
1006+
await mini.click()
1007+
await expect(preset).toHaveText("iPad mini")
1008+
await expect(preset).toBeFocused()
1009+
await expect(native).not.toHaveAttribute("data-width", fullWidth)
1010+
await viewport.click()
1011+
await expect(controls).toBeHidden()
1012+
await expect(native).toHaveAttribute("data-width", fullWidth)
1013+
await expect(native).toHaveAttribute("data-height", fullHeight)
1014+
await expect(root.getByRole("separator", { name: "Resize viewport width" })).toBeHidden()
1015+
await viewport.click()
1016+
await expect(preset).toHaveText("iPad mini")
1017+
await expect(width).toHaveValue("756")
1018+
await expect(height).toHaveValue("1158")
1019+
// Matching the preset's dimensions by hand still counts as Custom.
1020+
await width.fill("700")
1021+
await width.fill("756")
1022+
await expect(preset).toHaveText("Custom")
1023+
await preset.click()
1024+
await expect(option("Custom")).toBeChecked()
1025+
await moreDevices.hover()
1026+
await expect(mini).not.toBeChecked()
1027+
})
1028+
1029+
story("fits an exact viewport while resizing and rejects invalid edits", async ({ page }) => {
1030+
const { root, viewport, preset, option, scale, width, height } = viewportControls(page)
1031+
1032+
const native = root.getByTestId("native-Alpha")
1033+
await viewport.click()
1034+
await expect(width).toHaveValue("624")
1035+
await width.fill("1248")
1036+
await expect(scale).toHaveText("Fit - 50%")
1037+
await expect(width).toBeFocused()
1038+
await height.fill("5")
1039+
// Chromium needs whole native pixels: round the fitted height up.
1040+
await expectSize(native, 624, 3)
1041+
await expect(height).toBeFocused()
1042+
1043+
await resizePane(root, 328)
1044+
await expect(scale).toHaveText("Fit - 25%")
1045+
await expectSize(native, 312, 2)
1046+
await expect(width).toHaveValue("1248")
1047+
await expect(height).toHaveValue("5")
1048+
1049+
for (const edit of ["", "4097"]) {
1050+
await width.fill(edit)
1051+
await expect(width).toHaveValue(edit)
1052+
await expect(width).toHaveAttribute("aria-invalid", "true")
1053+
await expect(width).toHaveAccessibleDescription("Use whole numbers from 1 to 4096 for width and height.")
1054+
await expectSize(native, 312, 2)
1055+
}
1056+
1057+
await width.blur()
1058+
await expect(width).toHaveValue("1248")
1059+
await expect(width).not.toHaveAttribute("aria-invalid", "true")
1060+
await preset.click()
1061+
await option("Responsive").click()
1062+
await expect(preset).toHaveText("Responsive")
1063+
await expect(width).toHaveValue("312")
1064+
await expect(scale).toHaveText("Fit - 100%")
1065+
await resizePane(root, 640)
1066+
await expect(width).toHaveValue("624")
1067+
await expect(native).toHaveAttribute("data-width", "624")
1068+
})
1069+
1070+
story("resizes a device with the RTL side grip by pointer and keyboard", async ({ page }) => {
1071+
const { root, viewport, preset, option, scale, width, height } = viewportControls(page)
1072+
await root.evaluate((element) => element.setAttribute("dir", "rtl"))
1073+
await viewport.click()
1074+
await preset.click()
1075+
await option("Samsung Galaxy S26").click()
1076+
await scale.click()
1077+
await option("50%").click()
1078+
await expectSize(root.getByTestId("native-Alpha"), 180, 390)
1079+
const grip = root.getByRole("separator", { name: "Resize viewport width", exact: true })
1080+
1081+
const box = await grip.boundingBox()
1082+
1083+
if (!box) throw new Error("Missing viewport resize grip")
1084+
const x = box.x + box.width / 2
1085+
1086+
const y = box.y + box.height / 2
1087+
await page.mouse.move(x, y)
1088+
await page.mouse.down()
1089+
await page.mouse.move(x - 12, y)
1090+
// Both edges move 12 screen pixels, or 24 guest CSS pixels each at 50% scale.
1091+
await expect(width).toHaveValue("408")
1092+
await expect(height).toHaveValue("780")
1093+
await expect(preset).toHaveText("Custom")
1094+
await expectSize(root.getByTestId("native-Alpha"), 204, 390)
1095+
await expect(root.getByTestId("native-Alpha")).toHaveAttribute("data-visible", "true")
1096+
await expect(root.locator('img[elementtiming="embed-snapshot"]')).toHaveCount(0)
1097+
await page.mouse.up()
1098+
await grip.press("Shift+ArrowRight")
1099+
await expect(width).toHaveValue("398")
1100+
})
1101+
1102+
story("pins the responsive dimensions when a manual preview scale is selected", async ({ page }) => {
1103+
const { root, viewport, preset, option, scale, width, height } = viewportControls(page)
1104+
1105+
const native = root.getByTestId("native-Alpha")
1106+
await viewport.click()
1107+
await expect(width).toHaveValue("624")
1108+
const responsiveHeight = await height.inputValue()
1109+
await expect(scale).toHaveText("Fit - 100%")
1110+
await scale.click()
1111+
const menu = page.getByRole("menu")
1112+
await expect(menu.getByRole("menuitemradio")).toHaveText([
1113+
"Fit to pane",
1114+
"50%",
1115+
"75%",
1116+
"100%",
1117+
"125%",
1118+
"150%",
1119+
"200%",
1120+
])
1121+
const fit = option("Fit to pane")
1122+
await expect(fit).toBeChecked()
1123+
const double = option("200%")
1124+
await double.click()
1125+
await resizePane(root, 400)
1126+
await expect(scale).toHaveText("200%")
1127+
await expect(preset).toHaveText("Custom")
1128+
await expect(width).toHaveValue("624")
1129+
await expect(height).toHaveValue(responsiveHeight)
1130+
1131+
await width.fill("120")
1132+
await height.fill("80")
1133+
await expectSize(native, 240, 160)
1134+
await scale.click()
1135+
await expect(double).toBeChecked()
1136+
await fit.click()
1137+
await expect(scale).toHaveText("Fit - 100%")
1138+
await expectSize(native, 120, 80)
1139+
})
1140+
1141+
story("keeps the selected device and its rotated viewport with its browser tab", async ({ page }) => {
1142+
const { root, viewport, preset, moreDevices, option, width, height, scale, rotate } = viewportControls(page)
1143+
1144+
const switchTab = root.getByRole("button", { name: "Switch browser tab", exact: true })
1145+
await viewport.click()
1146+
await scale.click()
1147+
await option("50%").click()
1148+
await preset.click()
1149+
await moreDevices.hover()
1150+
const pixel = option("Pixel 10")
1151+
await pixel.click()
1152+
await expect(preset).toHaveText("Pixel 10")
1153+
await rotate.click()
1154+
await expectSize(root.getByTestId("native-Alpha"), 462, 206)
1155+
1156+
await switchTab.click()
1157+
await expect(root.getByTestId("native-Second")).toHaveAttribute("data-visible", "true")
1158+
await expect(preset).toHaveText("Responsive")
1159+
await width.fill("200")
1160+
await height.fill("180")
1161+
const second = root.getByTestId("native-Second")
1162+
await expectSize(second, 200, 180)
1163+
await expect(scale).toHaveText("Fit - 100%")
1164+
1165+
// Wrapping the toolbar moves the centered native view on both axes without changing its size.
1166+
await page.evaluate(() => document.fonts.ready.then(() => undefined))
1167+
1168+
const embed = root.locator('[data-component="browser-preview"] > div:first-child')
1169+
1170+
const wide = await embed.boundingBox()
1171+
await resizePane(root, 320)
1172+
const narrow = await embed.boundingBox()
1173+
1174+
if (!wide || !narrow) throw new Error("Missing preview bounds")
1175+
expect(narrow.x).toBeLessThan(wide.x)
1176+
expect(narrow.y).toBeGreaterThan(wide.y)
1177+
await expect(second).toHaveAttribute("data-x", String(Math.round(narrow.x)))
1178+
await expect(second).toHaveAttribute("data-y", String(Math.round(narrow.y)))
1179+
await expectSize(second, 200, 180)
1180+
1181+
await switchTab.click()
1182+
await expect(root.getByTestId("native-Alpha")).toHaveAttribute("data-visible", "true")
1183+
await expect(width).toHaveValue("924")
1184+
await expect(height).toHaveValue("412")
1185+
await expect(preset).toHaveText("Pixel 10")
1186+
await expect(scale).toHaveText("50%")
1187+
await preset.click()
1188+
await moreDevices.hover()
1189+
await expect(pixel).toBeChecked()
9311190
})

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.