Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulp refresh active tab after code change in chrome extension

I'm developing a chrome extension and I want to automatically refresh the active tab after a code change

I got gulp-open to work so I don't need to navigate to chrome://extensions anymore and manually click "reload"

now only the active tab refresh remains

I've tried gulp-livereload but couldn't get it to work for developing a chrome extension

any ideas how to approach this?

like image 450
goldylucks Avatar asked Oct 30 '22 13:10

goldylucks


1 Answers

Could you post the code of your chrome extension? Without much info, I hope this is helpful. You can inject the code below to refresh the page after the chrome extension is reloaded:

chrome.tabs.query({
    active: true,               // Select active tabs
    lastFocusedWindow: true     // In the current window
}, function(tabs) {
    // Since there can only be one active tab in one active window, 
    //  the array has only one element
    var tab = tabs[0];
    // Javascript to reload the page
    var code = 'window.location.reload();';
    // Execute the code for the current tab
    chrome.tabs.executeScript(tab.id, {code: code});
});
like image 67
jianweichuah Avatar answered Nov 09 '22 08:11

jianweichuah