javascript - why is this chrome.browserAction.setIcon method not working? -


i'm looking @ documentation page , can't figure out whats wrong in code:

chrome.browseraction.seticon({   details.imagedata = {     "48": "icons/iconfavorite48x.png",     "64": "icons/iconfavorite64x.png",     "128": "icons/iconfavorite128x.png"   } }); 

the documentaion says :

note 'details.imagedata = foo' equivalent 'details.imagedata = {'19': foo}'

so i'm extremely confused

your code big syntax error. javascript object literal expects list of pairs key: value. can't (and don't need) assignments there in key part.

so, fixing only syntax error, be:

// still wrong: chrome.browseraction.seticon({   imagedata : {     "48": "icons/iconfavorite48x.png",     "64": "icons/iconfavorite64x.png",     "128": "icons/iconfavorite128x.png"   } }); 

this fail. imagedata expects binary blobs of pixel data obtained, example, <canvas>. if want supply paths, need use path property:

// still wrong: chrome.browseraction.seticon({   path : {     "48": "icons/iconfavorite48x.png",     "64": "icons/iconfavorite64x.png",     "128": "icons/iconfavorite128x.png"   } }); 

note can provide sizes expects. if include other, fail. quoting docs:

if number of image pixels fit 1 screen space unit equals scale, image size scale * 19 selected. scales 1 , 2 supported.

a normal-sized icon 19x19 pixels; on high-dpi screens chrome may show 38x38 icon.

update: since chrome has switched material design in 53, expects 16x16 , 32x32 respectively. can supply both old , new sizes without errors.

so can this:

// correct chrome.browseraction.seticon({   path : {     "19": "icons/iconfavorite19x.png",     "38": "icons/iconfavorite38x.png"   } });  // correct chrome.browseraction.seticon({   path : {     "19": "icons/iconfavorite19x.png"   } });  // correct chrome.browseraction.seticon({   path : "icons/iconfavorite19x.png" }); 

the images don't have have these dimensions, scaled if necessary; it's of course better exact.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -