Skip to content

Commit

Permalink
Fix iframe detection
Browse files Browse the repository at this point in the history
Fixes #138
  • Loading branch information
tomayac committed Feb 27, 2023
1 parent b52e7bf commit 3876499
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 41 deletions.
16 changes: 16 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,21 @@ <h1>Browser-FS-Access.js Demo</h1>
>.
</p>
<pre></pre>
<div class="iframes">
<h2>In same-origin iframe</h2>
<p>
If above it says "Using the File System Access API", then it should say
so in the iframe.
</p>
<iframe src="."></iframe>
<h2>In cross-origin iframe</h2>
<p>
Cross-origin iframes cannot use the File System Access API, so it uses
the fallback.
</p>
<iframe
src="https://tomayac.github.io/cross-origin-browser-fs-access/"
></iframe>
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions demo/script.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,7 @@ import { imageToBlob } from './image-to-blob.mjs';
saveBlobButton.disabled = false;
saveResponseButton.disabled = false;
})();

if (window.self !== window.top) {
document.querySelector('.iframes').remove();
}
10 changes: 10 additions & 0 deletions demo/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ img {
code {
font-family: ui-monospace, monospace;
}

.supported {
color: green;
}

iframe {
width: 100%;
height: 400px;
border: solid 1px #000;
}
91 changes: 54 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "browser-fs-access",
"version": "0.32.1",
"version": "0.33.0",
"description": "File System Access API with legacy fallback in the browser.",
"type": "module",
"source": "./src/index.js",
Expand Down Expand Up @@ -50,7 +50,7 @@
},
"homepage": "https://github.com/GoogleChromeLabs/browser-fs-access#readme",
"devDependencies": {
"eslint": "^8.34.0",
"eslint": "^8.35.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.6.0",
"http-server": "^14.1.1",
Expand Down
5 changes: 3 additions & 2 deletions src/supported.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ const supported = (() => {
} catch {
return false;
}
} else if ('showOpenFilePicker' in self) {
return 'showOpenFilePicker';
}
if ('showOpenFilePicker' in self) {
return true;
}
return false;
})();
Expand Down

0 comments on commit 3876499

Please sign in to comment.