When Google removed the dedicated Maps tab from search results, I decided to take matters into my own hands by creating a Chrome extension that restores this beloved feature. Sometimes the best solutions can come from solving your own pain points!
The extension is a testament to the power of web technologies and how developers can quickly adapt to changes in user experience. Thanks to Chrome's extension architecture - specifically content scripts - we can dynamically modify web pages to meet user needs.
A cool part of this extension is the use of a MutationObserver
. MutationObserver is a powerful API that allows us to watch DOM changes in real-time!
const observer = new MutationObserver((mutations, obs) => {
const tabsContainer = document.querySelector('div[role="navigation"] div[role="list"]');
if (tabsContainer) {
createMapsTab();
obs.disconnect();
makeImageClickable();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
What's going on here?
- MutationObserver watches for changes in the DOM
- We're looking specifically for the navigation tabs container
- Once found, we create our custom "Maps" tab
- obs.disconnect() stops observing to prevent unnecessary processing
- This approach ensures we inject our tab dynamically, regardless of how the page loads
Top comments (0)