简体   繁体   English

我可以更改/覆盖 window.getSelection() 的定义吗?

[英]can I change / override definition of window.getSelection()?

I would like to know how can I change the definition of a native JS function.我想知道如何更改本机 JS function 的定义。

I need to do this in order to test an exploit for a Chrome extension that my team is developing.我需要这样做以测试我的团队正在开发的 Chrome 扩展程序的漏洞利用。 Specifically, I want the window.getSelection() function to return a value of my choice instead of actual selected text in screen.具体来说,我希望window.getSelection() function 返回我选择的值,而不是屏幕中实际选择的文本。

You probably want to 'patch' the getSelection function, so您可能想要'patch' getSelection function,所以

var originalGetSelection = window.getSelection;
window.getSelection = function() {
// your own stuff here
const args = Array.prototype.slice.call(arguments); // convert arguments as array of
return originalGetSelection.apply(window, args);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM