Can the window object be modified from a Chrome extension?

前端 未结 7 2049
甜味超标
甜味超标 2020-11-29 02:26

I would like to make a Chrome extension that provides a new object inside window. When a web page is viewed in a browser with the extension loaded, I would like

7条回答
  •  余生分开走
    2020-11-29 03:02

    I've been playing around with this. I found that I can interact with the window object of the browser by wrapping my javascript into a window.location= call.

    var myInjectedJs = "window.foo='This exists in the \'real\' window object';"
    window.location = "javascript:" + myInjectedJs;
    
    var myInjectedJs2 = "window.bar='So does this.';"
    window.location = "javascript:" + myInjectedJs2;
    

    It works, but only for the last instance of window.location being set. If you access the document's window object, it will have a variable "bar" but not "foo"

提交回复
热议问题