'How to update a tab opened with chrome.tabs.create({ url })

I'm creating a chrome extension and I want to open a tab with a button and with another button I want to refresh that page. Currently I'm using an event listener on a button and I can open a local html page in a new tab. But I don't know how to refresh/update that specific page.

window.addEventListener('DOMContentLoaded', function (){
    let shareButton = document.getElementById('focus');
    shareButton.addEventListener('click', function() { 
          chrome.tabs.create({ url: chrome.runtime.getURL("index.html") });
    });
});



Solution 1:[1]

To refresh that page or send data from the popup it's important that the popup isn't closed after opening the tab use the active property for this:

tab = chrome.tabs.create({ url, active: false })

afterwards you can refresh that tab or send a message:

chrome.tabs.sendMessage(tab.id, data, responseReceived)

Solution 2:[2]

Assuming your image is in the index folder, the path provided is incorrect. It should be:

<img src="./robot.svg" alt="" width="50" height="30" />

instead of

<img src="../robot.svg" alt="" width="50" height="30" />

Remove the extra dot and it should work fine

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 matthiasgiger
Solution 2 Karan Karpe