Skip to content

Commit 1f1de46

Browse files
authored
fix: safari renders images correctly (#753)
* fix: safari rendering images * test: run safari/webkit e2e tests * chore: lint fix and minor cleanup * chore: install playwright deps for webkit tests * chore: attempt to run webkit test on macos-latest * Revert "chore: attempt to run webkit test on macos-latest" This reverts commit 9f08bdd. * chore(ci): webkit caches playwright deps and uploads test artifacts * chore(ci): playwright project test-results use unique artifact name * chore(ci): webkit->safari so playwright tests dont run in CI
1 parent 6a2a49b commit 1f1de46

File tree

9 files changed

+1400
-940
lines changed

9 files changed

+1400
-940
lines changed

.github/workflows/main.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
if: always()
8787
uses: actions/upload-artifact@v4
8888
with:
89-
name: playwright-debug
89+
name: playwright-debug-chrome
9090
path: test-results
9191

9292
test-chrome-webworker:
@@ -153,11 +153,27 @@ jobs:
153153
with:
154154
node-version: lts/*
155155
- uses: ipfs/aegir/actions/cache-node-modules@main
156+
- name: Cache Playwright dependencies
157+
id: playwright-cache
158+
uses: actions/cache@v4
159+
with:
160+
path: ~/.cache/ms-playwright
161+
key: playwright-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
162+
restore-keys: |
163+
playwright-${{ runner.os }}-
164+
- run: npx playwright install --with-deps
165+
timeout-minutes: 10 # should take no longer than 2min
156166
- run: npm run --if-present test:webkit
157167
- uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
158168
with:
159169
flags: webkit
160170
files: .coverage/*,packages/*/.coverage/*
171+
- name: Upload Playwright artifacts
172+
if: always()
173+
uses: actions/upload-artifact@v4
174+
with:
175+
name: playwright-debug-webkit
176+
path: test-results
161177

162178
test-electron-main:
163179
needs: build

package-lock.json

Lines changed: 1332 additions & 937 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
"pretest:all": "run-s build",
2929
"test:all": "cross-env SHOULD_BUILD=false run-s 'test:iso -- -b false' 'test:node -- -b false' test:browsers",
3030
"test:iso": "aegir test -f dist-tsc/test/**/*.spec.js",
31-
"test:browsers": "playwright test -c playwright.config.js --project chromium firefox no-service-worker",
31+
"test:browsers": "playwright test -c playwright.config.js --project chromium firefox webkit no-service-worker",
3232
"test:chrome": "playwright test -c playwright.config.js --project chromium",
3333
"test:no-sw": "playwright test -c playwright.config.js --project no-service-worker",
3434
"test:firefox": "playwright test -c playwright.config.js --project firefox no-service-worker",
35+
"test:safari": "playwright test -c playwright.config.js --project safari",
3536
"test:deployed": "playwright test -c playwright.config.js --project deployed",
3637
"test:local-binary": "concurrently -k --success first -n \"binary,tests\" \"npm run start\" \"cross-env SHOULD_BUILD=false BASE_URL='http://localhost:3000' playwright test -c playwright.config.js --project deployed no-service-worker\"",
3738
"test:inbrowser-dev": "cross-env BASE_URL='https://inbrowser.dev' playwright test -c playwright.config.js --project deployed",

playwright.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ export default defineConfig({
5959
...devices['Desktop Firefox']
6060
}
6161
},
62+
{
63+
// NOTE: github CI isn't running these tests successfully, but they work locally.
64+
name: 'safari',
65+
use: {
66+
...devices['Desktop Safari']
67+
}
68+
},
6269
/**
6370
* Test a deployed site such as inbrowser.dev with `BASE_URL="https://inbrowser.dev" npm run test:deployed`
6471
* or inbrowser.link with `BASE_URL="https://inbrowser.link" npm run test:deployed`

src/sw.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,15 @@ async function fetchHandler ({ path, request, event }: FetchHandlerArg): Promise
557557
return await errorPageResponse(response)
558558
}
559559

560-
return response
560+
// Create a completely new response object with the same body, status, statusText, and headers.
561+
// This is necessary to work around a bug with Safari not rendering content correctly.
562+
const newResponse = new Response(response.body, {
563+
status: response.status,
564+
headers: response.headers,
565+
statusText: response.statusText
566+
})
567+
568+
return newResponse
561569
} catch (err: unknown) {
562570
log.trace('fetchHandler: error: ', err)
563571
const errorMessages: string[] = []

test-e2e/config-loading.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ test.describe('ipfs-sw configuration', () => {
3434
})
3535

3636
test('root config is propagated to subdomain', async ({ page, baseURL, rootDomain, protocol }) => {
37+
if (test.info().project.name === 'webkit') {
38+
// @see https://github.com/ipfs/in-web-browsers/issues/206
39+
test.skip()
40+
return
41+
}
3742
await page.goto(baseURL, { waitUntil: 'networkidle' })
3843
await waitForServiceWorker(page, baseURL)
3944
// set the config on the root..

test-e2e/first-hit.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ test.describe('first-hit ipfs-hosted', () => {
3838
})
3939

4040
test.describe('subdomain-routing', () => {
41+
test.beforeAll(async () => {
42+
if (test.info().project.name === 'webkit') {
43+
// @see https://github.com/ipfs/in-web-browsers/issues/206
44+
test.skip()
45+
}
46+
})
4147
test('redirects to ?helia-sw=<path> are handled', async ({ page, rootDomain, protocol }) => {
4248
const response = await page.goto('http://localhost:3334/ipfs/bafkqablimvwgy3y')
4349

@@ -101,6 +107,12 @@ test.describe('first-hit direct-hosted', () => {
101107
})
102108

103109
test.describe('subdomain-routing', () => {
110+
test.beforeAll(async () => {
111+
if (test.info().project.name === 'webkit') {
112+
// @see https://github.com/ipfs/in-web-browsers/issues/206
113+
test.skip()
114+
}
115+
})
104116
test('requests to new pages are redirected', async ({ page, rootDomain, protocol }) => {
105117
const response = await page.goto(`${protocol}//${rootDomain}/ipfs/bafkqablimvwgy3y`, { waitUntil: 'commit' })
106118

test-e2e/fixtures/config-test-fixtures.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ export const testSubdomainRouting = test.extend<{ rootDomain: string, baseURL: s
130130
rootDomain: [rootDomain, { scope: 'test' }],
131131
protocol: [baseURLProtocol, { scope: 'test' }],
132132
page: async ({ page, baseURL }, use) => {
133+
/**
134+
* if safari, skip subdomain routing tests
135+
*
136+
* @see https://github.com/ipfs/in-web-browsers/issues/206
137+
*/
138+
if (test.info().project.name === 'webkit') {
139+
testSubdomainRouting.skip()
140+
return
141+
}
142+
133143
await page.goto(baseURL, { waitUntil: 'networkidle' })
134144
await waitForServiceWorker(page, baseURL)
135145

test-e2e/subdomain-detection.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ test.describe('subdomain-detection', () => {
1313
routers.push(process.env.KUBO_GATEWAY)
1414
})
1515
test('path requests are redirected to subdomains', async ({ page, baseURL, rootDomain, protocol }) => {
16+
if (test.info().project.name === 'webkit') {
17+
// @see https://github.com/ipfs/in-web-browsers/issues/206
18+
test.skip()
19+
return
20+
}
21+
1622
await page.goto(baseURL, { waitUntil: 'networkidle' })
1723
await waitForServiceWorker(page, baseURL)
1824
await setConfig({

0 commit comments

Comments
 (0)