diff --git a/src/gui/src/css/feedback-embed.css b/src/gui/src/css/feedback-embed.css index cc04175ef..032e10619 100644 --- a/src/gui/src/css/feedback-embed.css +++ b/src/gui/src/css/feedback-embed.css @@ -12,4 +12,6 @@ body { /* A scroll over the scrim must not scroll the framing page behind it. */ html { overscroll-behavior: none; + /* Matches the frame's, so it stays transparent and follows the OS theme. */ + color-scheme: light dark; } diff --git a/src/gui/src/feedbackEmbed.browser.test.js b/src/gui/src/feedbackEmbed.browser.test.js index 4301a73da..9fe6bbf58 100644 --- a/src/gui/src/feedbackEmbed.browser.test.js +++ b/src/gui/src/feedbackEmbed.browser.test.js @@ -6,6 +6,7 @@ import { mkdtemp, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; +import { inflateSync } from 'node:zlib'; let browser; let server; @@ -74,7 +75,7 @@ beforeAll(async () => { }); + style="display:block;border:0;width:100vw;height:100vh;color-scheme:light dark">
`)); app.get('/embed/feedback', (_req, res) => { @@ -102,13 +103,26 @@ afterAll(async () => { }); /** A browser whose GUI origin is signed in with `token`, if any. */ -const signedIn = token => browser.newContext({ storageState: { +const signedIn = (token, options = {}) => browser.newContext({ ...options, storageState: { cookies: [], origins: token ? [{ origin, localStorage: [{ name: 'auth_token_v2', value: token }] }] : [], } }); const received = page => page.evaluate(() => window.received); +/** The [r, g, b] of one pixel of the page, from a screenshot. */ +const pixel = async (page, x, y) => { + const png = await page.screenshot({ clip: { x, y, width: 1, height: 1 }, animations: 'disabled' }); + const data = []; + for ( let at = 8; at < png.length; ) { + const length = png.readUInt32BE(at); + if ( png.toString('ascii', at + 4, at + 8) === 'IDAT' ) data.push(png.subarray(at + 8, at + 8 + length)); + at += 12 + length; + } + // One pixel: a filter byte, then its channels unchanged. + return [...inflateSync(Buffer.concat(data)).subarray(1, 4)]; +}; + describe('feedback embed', () => { it('sends feedback for the framing page as the user it names, then tells it', async () => { const context = await signedIn(sessionToken); @@ -162,6 +176,26 @@ describe('feedback embed', () => { } }, 30000); + it.each(['light', 'dark'])('lets the page show through under the scrim in %s mode', async (colorScheme) => { + const context = await signedIn(sessionToken, { colorScheme }); + try { + const page = await context.newPage(); + page.setDefaultTimeout(6000); + await page.goto(`${hostOrigin}/host?user=${sessionUser}`); + const frame = page.frameLocator('iframe'); + await frame.locator('.app-feedback-form').waitFor(); + expect(await frame.locator('body').evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches)) + .toBe(colorScheme === 'dark'); + await page.waitForTimeout(300); + // The red page, dimmed by the scrim, rather than an opaque frame. + const [red, green, blue] = await pixel(page, 10, 10); + expect(red).toBeGreaterThan(green + 40); + expect(green).toBe(blue); + } finally { + await context.close(); + } + }, 30000); + it('keeps the page behind from scrolling under the scrim', async () => { const context = await signedIn(sessionToken); try { diff --git a/src/puter-js/src/lib/guiEmbed.js b/src/puter-js/src/lib/guiEmbed.js index fbdc763ae..7c73fd266 100644 --- a/src/puter-js/src/lib/guiEmbed.js +++ b/src/puter-js/src/lib/guiEmbed.js @@ -67,8 +67,9 @@ export const showFeedbackEmbed = ({ guiOrigin, userUuid }) => new Promise((resol // The embed allows a framing page it can name from the referrer. frame.setAttribute('referrerpolicy', 'origin'); // A frame whose color-scheme differs from its document's is painted - // opaque; the embed declares none. - frame.style.cssText = 'display:block;width:100%;height:100%;border:0;background:transparent;color-scheme:normal;'; + // opaque, so this matches the embed's. WebKit also gives the frame this + // scheme as its preferred one, so it has to follow the OS. + frame.style.cssText = 'display:block;width:100%;height:100%;border:0;background:transparent;color-scheme:light dark;'; dialog.append(style, frame); let settled = false; diff --git a/src/puter-js/src/lib/guiEmbed.test.js b/src/puter-js/src/lib/guiEmbed.test.js index a46858a7c..126056507 100644 --- a/src/puter-js/src/lib/guiEmbed.test.js +++ b/src/puter-js/src/lib/guiEmbed.test.js @@ -50,6 +50,8 @@ describe('showFeedbackEmbed', () => { expect(url.search).toBe(''); expect(new URLSearchParams(url.hash.slice(1)).get('user')).toBe(USER); expect(frame().getAttribute('referrerpolicy')).toBe('origin'); + // WebKit hands the frame this as its preferred scheme; it must follow the OS. + expect(frame().getAttribute('style')).toContain('color-scheme: light dark'); expect(frame().closest('dialog').open).toBe(false); });