Skip to content

Commit 9fe37c8

Browse files
committed
fix: add in chrome and mozilla handles
1 parent 10e1be5 commit 9fe37c8

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

www/pages/_layout.html

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,33 @@
3232
return fallBackCopy(strToCopy);
3333
}
3434

35-
navigator.permissions
36-
.query({ name: "clipboard-write" })
37-
.then((result) => {
38-
if (result.state == "granted" || result.state == "prompt") {
39-
navigator.clipboard.writeText(strToCopy).then(
40-
function () {
41-
// ignore and digest
42-
},
43-
function () {
44-
return fallBackCopy(strToCopy);
45-
}
46-
);
47-
} else {
35+
function _runCopy() {
36+
navigator.clipboard.writeText(strToCopy).then(
37+
function () {
38+
// ignore and digest
39+
},
40+
function () {
4841
return fallBackCopy(strToCopy);
4942
}
50-
});
43+
);
44+
}
45+
46+
// If not chrome, then just run the copy and if it errors
47+
// let the fallback handle it
48+
// If chrome, then the permission is checked and if no permissions
49+
// are enabled then the fallback is run
50+
if (!navigator.userAgent.includes("Chrome")) {
51+
_runCopy();
52+
} else {
53+
navigator.permissions
54+
.query({ name: "clipboard-write" })
55+
.then((result) => {
56+
if (result.state == "granted" || result.state == "prompt") {
57+
} else {
58+
return fallBackCopy(strToCopy);
59+
}
60+
});
61+
}
5162
}
5263

5364
function fallBackCopy(strToCopy) {

0 commit comments

Comments
 (0)