javascript - What does getBackgroundPage() function return exactly? (Google Chrome) -


i'm trying return first* image displayed on webpage code:

img.src = chrome.extension.getbackgroundpage().imagesrc[0]

0 represents first image. seems work. however, getbackgroundpage() functional tab opened. want work if user using different webpage.

in discovering how find first image of website isn't runnning, first have understand chrome.extension.getbackgroundpage() returns. string? or url?

i've tried replacing with, [document.getelementid("hi").getsrc.]imagesrc[0]...hi represented in htm as div src of url want...but not work. solutions?

why trying use extension this?

try this;

document.getelementsbytagname('img')[0]; 

this vanilla javascript , needs no plugins, extensions or particular browsers.

edit

to answer question;

returns javascript 'window' object background page running inside current extension. returns null if extension has no background page.

thats according the docs.

edit 2

ok, so, chrome.extension.getbackgroundpage() returns 'window' object, means may able this;

w = chrome.extension.getbackgroundpage() w.document.getelementsbytagname('img')[0]; 

edit 3

once have dom object, can attributes so;

document.getelementsbytagname('img')[0].src; 

edit 4

apologies not understanding initially. have @ source 'bitbucket notifier' extension on chrome. most importantly file.

it polls bitbucket every 5 seconds (if i'm reading correctly) , returns data site extension.

could used in extension?


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -