Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

javascript - How to get another web page data within background script of Chrome extension?

I'm trying to read some data from HTML web page from specified web site, in my Chrome extension. I tried many scripts but not succeed, and now trying with following..

chrome.webRequest.onBeforeRequest.addListener(
        function(details)
        {
          alert('ok');
          alert( details.requestBody);
        },
        {
          urls: ["https://www.thefreedictionary.com/test"]
        },
        ['requestBody']
     );

The scripts runs without error, but callback never fires. I tried with different url's, but none of them worked. The alert never shown.

Can anyone find what I'm doing wrong here?

I just want to read web page from background script. I'm interested to use solution including something like below to define UserAgent.

    myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";//"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0";

Any help would be highly appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...