0

So recently I'm developing a CRX extension, and I need to transfer some of JSON-formatted data from page to content-script, but the problem I encountered is that native JSON.stringify function is rewrited by some JS in the page, So the following JS does not work.

  var dataBridge = document.createElement('script');
  dataBridge.type = 'text/javascript';
  document.body.setAttribute('dataBridge',JSON.stringify(PageData));
  document.head.appendChild(dataBridge);
  document.head.removeChild(dataBridge);
  PageData = document.body.getAttribute('dataBridge');
  PageData = JSON.parse(PageData);

So, is it possible for me to access native functions if it is "Hijacked"?, If not, am I possible to transfer those JSON-formatted data by some methods else? I'm afraid that I cannot just write lots of quotes, which can make my code hardly to be obfuscated.

Winslow
  • 1
  • 2
  • You can also use `CustomEvent` + dispatchEvent so there's no need for JSON, [example](https://stackoverflow.com/a/19312198). – wOxxOm Sep 11 '21 at 09:46

0 Answers0