How to create a Chrome extension that adds code to the page

Asked

Viewed 527 times

0

Extension Safe or not:

I need to add in a specific page (preferably) or in all cases if a certain code is simpler.

This here works:

var meucode = 'alert("oi");';
var script = document.createElement('script');
var code = document.createTextNode('(function() {' + meucode + '})();');
script.appendChild(code);
(document.body || document.head).appendChild(script);

He gives an alert on every page I enter...

Well, it is possible to adapt this to add an "image" on the site that the person enters.

  • 1

    Have you tried it and see what happens?

  • 2

    Hello Marcelo, On this site is a guide on how to create an extension for Chrome https://developer.chrome.com/extensions/getstarted, after reading this one it is interesting to open this https://developer.chrome.com/extensions/overview which shows the architecture of an extension (how much files, nomenclature and basic content they need), finally this one https://developer.chrome.com/extensions/api_index shows some of the Apis available for Javascript to interact with the browser. I hope this helps.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.