Skip to content

Commit

Permalink
Worked around CSP issue with unsupported browsers.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Jul 27, 2024
1 parent 5fedeee commit e73993c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
19 changes: 1 addition & 18 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -400,23 +400,6 @@ <h1>Unsupported Browser</h1>
Wordplay, you'll need to upgrade to a more recent version.</p
>
</div>
<script nonce="%sveltekit.nonce%">
function supportsRegexNegativeLookBehind() {
try {
return 'hi'.replace(new RegExp('(?<!hi)hi', 'g'), 'ho');
} catch (error) {
return false;
}
}

function supportsAt() {
return [].at !== undefined;
}

const unsupported = document.getElementById('unsupported');
if (!supportsRegexNegativeLookBehind() || !supportsAt())
unsupported.style.display = 'block';
else unsupported.remove();
</script>
<script src="/scripts/unsupported.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions static/scripts/unsupported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function supportsRegexNegativeLookBehind() {
try {
return 'hi'.replace(new RegExp('(?<!hi)hi', 'g'), 'ho');
} catch (error) {
return false;
}
}

function supportsAt() {
return [].at !== undefined;
}

const unsupported = document.getElementById('unsupported');
if (unsupported) {
if (!supportsRegexNegativeLookBehind() || !supportsAt())
unsupported.style.display = 'block';
else unsupported.remove();
}

0 comments on commit e73993c

Please sign in to comment.