javascript - Chrome extension: not all API's present after chrome.runtime.reload() -


i have problem chrome extension that depends on chrome.tabs api.

my extension running normally. chrome.runtime.reload() , works without problems, , (i have neither been able predict when or reliably replicate it) when background script comes after restart chrome.tabs reference undefined. since depend on api extension can't start. scenario can detected, when try chrome.runtime.reload(), chrome.runtime.reload undefined. don't have method restart again.

i realise ought develop soft restart capabilities extension return blank state, that's work intensive, wanted ask community if else have experience problem, , in case, how have solved it?

here permissions manifest.json file:

 "permissions": [    "tabs",    "contextmenus",    "webnavigation",    "webrequest",    "webrequestblocking",    /* whitelisted web urls... */ 

thanks lot @xan pointing me towards this other question seems cover exact same phenomenon.

i have decided enough indications point towards being bug in chrome's handling of background pages.

i have additional observations:

  • the question pointed @xan have references bug in chrome's background pages.

  • when replicated bug calling chrome.runtime.reload() in background page's developer tools console found chrome.runtime.reload() available usual extension's popup ui.

  • background pages not (yet) deprecated, first line in documentation recommends migrating event pages instead, can't possibly high on chromium team's priority list. in other words, consider risk of bug - if 1 - have high risk of being categorized 'wontfix', therefore, looks unproductive try wait out fix.

therefore, have devised workaround think satisfactory until have resources either develop soft-restart capabilities in extension or migrate event pages:

given that:

  • most of extensions functionality triggered via chrome browseraction. before browser action starts render, can post message background page know call immediately.

  • when extension have started normally, fix no-op invisible end-user.

  • since fix normal operation no-op fix won't hurt extension should chromium team fix bug in future release.

  • "dead" background pages have failed register any message listener. if background page doesn't respond safety check message, popup can fix broken state restarting extension.

this comes @ cost: if popup times out waiting 'safety net' message , restarts, popup ui brutally closed without warning under end user's feet. not nice - after consideration have decided think behaviour far preferable extension silently stopping working can now.

comment if have further ideas!


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -