Skip to content

Commit 3876499

Browse files
committed
Fix iframe detection
Fixes #138
1 parent b52e7bf commit 3876499

File tree

6 files changed

+89
-41
lines changed

6 files changed

+89
-41
lines changed

demo/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,21 @@ <h1>Browser-FS-Access.js Demo</h1>
4444
>.
4545
</p>
4646
<pre></pre>
47+
<div class="iframes">
48+
<h2>In same-origin iframe</h2>
49+
<p>
50+
If above it says "Using the File System Access API", then it should say
51+
so in the iframe.
52+
</p>
53+
<iframe src="."></iframe>
54+
<h2>In cross-origin iframe</h2>
55+
<p>
56+
Cross-origin iframes cannot use the File System Access API, so it uses
57+
the fallback.
58+
</p>
59+
<iframe
60+
src="https://tomayac.github.io/cross-origin-browser-fs-access/"
61+
></iframe>
62+
</div>
4763
</body>
4864
</html>

demo/script.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,7 @@ import { imageToBlob } from './image-to-blob.mjs';
199199
saveBlobButton.disabled = false;
200200
saveResponseButton.disabled = false;
201201
})();
202+
203+
if (window.self !== window.top) {
204+
document.querySelector('.iframes').remove();
205+
}

demo/style.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@ img {
3434
code {
3535
font-family: ui-monospace, monospace;
3636
}
37+
38+
.supported {
39+
color: green;
40+
}
41+
42+
iframe {
43+
width: 100%;
44+
height: 400px;
45+
border: solid 1px #000;
46+
}

package-lock.json

Lines changed: 54 additions & 37 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browser-fs-access",
3-
"version": "0.32.1",
3+
"version": "0.33.0",
44
"description": "File System Access API with legacy fallback in the browser.",
55
"type": "module",
66
"source": "./src/index.js",
@@ -50,7 +50,7 @@
5050
},
5151
"homepage": "https://github.com/GoogleChromeLabs/browser-fs-access#readme",
5252
"devDependencies": {
53-
"eslint": "^8.34.0",
53+
"eslint": "^8.35.0",
5454
"eslint-config-google": "^0.14.0",
5555
"eslint-config-prettier": "^8.6.0",
5656
"http-server": "^14.1.1",

src/supported.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ const supported = (() => {
3636
} catch {
3737
return false;
3838
}
39-
} else if ('showOpenFilePicker' in self) {
40-
return 'showOpenFilePicker';
39+
}
40+
if ('showOpenFilePicker' in self) {
41+
return true;
4142
}
4243
return false;
4344
})();

0 commit comments

Comments
 (0)