Skip to content

Commit

Permalink
Merge pull request #71 from discoveryjs/clipboard-fallback
Browse files Browse the repository at this point in the history
Fallback to textarea copy to clipboard for unsecure http hosts
  • Loading branch information
exdis authored May 14, 2021
2 parents 612a4bf + 566b317 commit 98274f3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.11.1 (10-05-2021)

* Fixed copying JSON to clipboard on http hosts

## 1.11.0 (03-04-2021)

* Improved data loading and page style changes rollback when data is not a JSON or broken JSON
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsondiscovery",
"version": "1.11.0",
"version": "1.11.1",
"description": "DiscoveryJson",
"author": "exsdis@gmail.com",
"license": "MIT",
Expand Down
8 changes: 7 additions & 1 deletion src/discovery/copy-to-clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ export async function copyToClipboard(text) {
try {
await navigator.clipboard.writeText(text);
} catch (err) {
console.error(err); // eslint-disable-line no-console
// clipboard textarea fallback
const textarea = document.createElement('textarea');
textarea.innerText = text;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
}

flashMessage('JSON copied to clipboard', 'success');
Expand Down

0 comments on commit 98274f3

Please sign in to comment.