Google plug-in modifies navigator.platform

Without further ado, the preface contains a few key points after the blogger’s practice, pay attention!

sequence:

        1. The time to change navigator.platform is when the page html comes out, but the head and body tags have not yet come out.

        2. Object.defineProperty can only be introduced through preloading! (Understand this sentence carefully)

        3. The web_accessible_resources in manifest.json must be configured with a whitelist!

        4. Blogger’s WeChat public account: Programmer Wild Area  , follow and reply “join the group”.

text:

        I try to write as detailed as possible, so don’t skip reading every word!

        1. Your content-scriptx.js is only 3 lines of code, don’t! put! exist! document.addEventListener('DOMContentLoaded', remember!

content-scriptx.js
(function() {
	injectCustomJS('js/injection/x1.js');
})();

In fact, the key lies in the injection method injectCustomJS , because at this time your page is loaded as shown below

So at this time , it is useless for    you to directly document.body.appendChild(temp); because body and head do not exist at all.

The method blogger of injectCustomJS posted it on the public account: Programmer Wild Area. Follow and reply " inject js " and it will come out.

You name x1.js yourself, the path must be correct anyway

x1.js
(function() {
	'use strict';
	Object.defineProperty(navigator,'platform',{get:function(){return 'iPhone';}});
	console.log(navigator.platform)//博主公众号:程序员野区
})();

Okay, let’s talk about some things to pay attention to.

manifest.json content_scripts js _ _

Remember to whitelist web_accessible_resources in manifest.json

If you are still confused after reading this, go directly to the public account: Programmer Wilderness Zone and send a private message to the blogger. The blogger will contact you remotely when he has time.

Supongo que te gusta

Origin blog.csdn.net/xuelang532777032/article/details/132695320
Recomendado
Clasificación