0

It has a web page using MircrosoftAjax to create the confirmation dialog that ComponentID could be found by $find (or Sys.Application.findComponent) in Chrome console and Sys.Application.getComponents got the ID Component list as well,but when I moved the code injecting into Content Script of Chrome extension,The result always returned 'NULL' except for DOM operation . I just want to change the Component's property to achieve automatical confirmation without manual clicking,but it seems hard to do. This is my code:

 $(document).ready(function(){  

    Sys.Application.getComponents() //return 'NULL'
    Sys.Application.findComponent('sth')._ConfirmOnFormSubmit=true  //return 'Cannot set property '_ConfirmOnFormSubmit' of null '
    })

    function pageLoad(sender,args) {
//Sys.Application.initialize()
console.log($find('sth'))  //return 'NULL'
function confirm() {return true} //seems to approach the fact working well that bypassed the dialog in chrome console  but still not working in Content Script
}

Why has the different result between Content and Console? How should I do the right way?

I appreciate so much if someone can give me a solution.

Best Regards.

supertu
  • 3
  • 3

1 Answers1

0

The reason you see this behavior is that content scripts live in an isolated context. They don't have access to page's JavaScript and its state.

To test, you can open the console and at the top switch context from <top frame> to your extension's context. You'll see different console results.

To fix this situation, you need to inject yet another time, this time from the content script into the page's context; you can then communicate data between the two using custom events or window.postMessage().

Here's a canonical question for that.

Community
  • 1
  • 1
Xan
  • 74,770
  • 16
  • 179
  • 206
  • Oh,Xan! That's great for your help. The answer for me is much useful and I will absorb the information gradually. Thanks in advance :) – supertu May 30 '14 at 08:51