-2

I can't find the solution to this.

Imagine scenario:

You are entering LinkedIn, doing some search and then running browser extension to copy to clipboard actual source of the website - the same code as you can see at a right mouse click and Inspect.

Is this possible? Is there already any solution to that?

user9088454
  • 1,076
  • 1
  • 15
  • 45
proada
  • 19
  • 2

1 Answers1

1

You can get the HTML of the entire document using

document.documentElement.outerHTML

and then copy that string to the clipboard:

const { outerHTML } = document.documentElement;
const textarea = document.body.appendChild(document.createElement('textarea'));
textarea.value = outerHTML;
textarea.focus();
textarea.select();
document.execCommand('copy');
textarea.remove();
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320