Screen Share Failure Led Me to Build a Chrome Extension
In this article
When your screen share fails mid-presentation, you lose time, credibility, and sometimes the meeting itself. This guide walks through the exact failure that pushed me to build a Chrome extension that solves the problem automatically — and shows you how to create your own version, even if you've never written an extension before.
What You'll Need
- Google Chrome (or any Chromium browser like Edge or Brave)
- A text editor (VS Code, Notepad++, or even plain Notepad)
- Basic knowledge of JavaScript and HTML (a little goes a long way)
- About 30 minutes of focused time
Step-by-Step
- Identify the exact failure point. In my case, the screen share failed because Chrome's
getDisplayMedia()promise never resolved when the user clicked the share button — a known issue when the browser window loses focus or when multiple monitors have different scaling. Write down what error you see (or don't see) so you know what to fix. - Create the extension folder. Make a new folder on your computer, e.g.,
screen-share-fix. This will hold all your extension files. - Write the manifest file. Create a file named
manifest.jsoninside that folder. For Chrome's current Manifest V3, paste this:{ "manifest_version": 3, "name": "Screen Share Fixer", "version": "1.0", "permissions": ["activeTab", "scripting"], "background": { "service_worker": "background.js" }, "action": { "default_popup": "popup.html" } }This tells Chrome the extension exists, what permissions it needs, and what files to load. - Create the background script. Make a file called
background.js. This runs in the background and will handle the core logic. For my fix, I needed to re-trigger the screen share request after a short delay if the first one hung. Here's a simplified version:chrome.action.onClicked.addListener((tab) => { chrome.scripting.executeScript({ target: { tabId: tab.id }, func: () => { // Simulate a fresh user gesture setTimeout(() => { navigator.mediaDevices.getDisplayMedia({ video: true }) .then(stream => { // Attach stream to a video element or send to your app console.log('Screen share started'); }) .catch(err => console.error('Failed:', err)); }, 100); } }); });The key trick: by injecting a script that callsgetDisplayMedia()inside asetTimeout, you create a new user gesture context that often bypasses the stuck promise. - Add a popup for user control. Create
popup.htmlandpopup.jsso you can click the extension icon and start the fix manually. The popup just needs a button that calls the same injected script. Keep it simple:<button id="fix">Retry Screen Share</button> <script src="popup.js"></script>
Inpopup.js, add a click listener that runs the same injection code. - Load the extension in Chrome. Open
chrome://extensions, enable "Developer mode" (toggle in the top right), click "Load unpacked", and select your folder. The extension should appear in your toolbar. - Test it on a real page. Go to any website that uses screen sharing (like Google Meet or a custom app), click your extension's icon, and see if the share prompt appears. If it does, you've fixed the hang.
- Refine for your specific case. My failure also involved a multi-monitor setup where the wrong screen was captured. I added a small options page to let users choose which screen to share by name. You can do the same by reading
navigator.mediaDevices.enumerateDevices()and filtering for display devices.
Common Mistakes
- Forgetting to update the manifest version. If you copy old Manifest V2 code, Chrome will block it. Always use V3 for new extensions.
- Calling
getDisplayMedia()without a user gesture. The browser requires a direct user click or keypress. If you call it from a timer or async callback without a fresh gesture, it will fail silently. - Not handling the promise rejection. If the user cancels the prompt, the promise rejects. Without a
.catch(), you'll get an unhandled error and no feedback. - Using
chrome.tabs.executeScriptin V3. That method is deprecated; usechrome.scripting.executeScriptwith thescriptingpermission.
Tips
- Test on a clean profile. Some failures come from other extensions interfering. Create a new Chrome profile to isolate your extension.
- Log everything. Use
console.login your background script and open the service worker console (fromchrome://extensions→ your extension → "service worker" link) to see errors. - Keep permissions minimal. Only ask for
activeTabandscripting— that's all you need for this fix. More permissions scare users and slow review. - Use the
chrome.storageAPI to remember user preferences. For example, save which screen they prefer so the next share uses it automatically.
Troubleshooting
- The extension doesn't appear in the toolbar. Reload the extension from
chrome://extensionsand ensure the manifest is valid (Chrome will show an error if not). - The share prompt still doesn't appear. Check the service worker console for errors. If you see "Cannot read properties of undefined", your injection script isn't running — verify the
activeTabpermission and that you're on a real page (not chrome://internal pages). - The share starts but freezes. That's often a different issue — maybe the video track's resolution is too high. Try forcing a lower resolution by calling
stream.getVideoTracks()[0].applyConstraints({ width: 1280, height: 720 }). - Works on some sites but not others. Some sites override
navigator.mediaDevicesor use their own capture logic. In that case, you may need to inject your script into the page's context usingworld: 'MAIN'in theexecuteScriptcall. - After updating the extension, changes don't take effect. Always click the refresh icon on your extension card in
chrome://extensionsafter editing files.
Frequently Asked Questions
Do I need to know React or a framework to build this?
No. Plain JavaScript and HTML are enough. The extension runs in the browser, so no build tools are required.
Can I publish this to the Chrome Web Store?
Yes, but you'll need to pay a one-time developer registration fee and go through a review. For personal use, the unpacked version is fine.
Will this work on Firefox or Safari?
Firefox supports a similar API but uses browser instead of chrome. Safari has its own extension system with different APIs. This guide is Chrome-specific.
Is there any risk to my computer from running an unpacked extension?
Only if you install extensions from untrusted sources. Since you're writing the code yourself, you can see exactly what it does. Chrome also sandboxes extensions to limit damage.
What if the screen share failure is caused by the website, not the browser?
Then your extension won't help. You can test by trying screen share on a different site. If it works there, the problem is site-specific.
Can I automate the fix so I don't have to click the extension every time?
Yes, you can use chrome.tabs.onUpdated to detect when a page loads and automatically inject the fix if the page has a screen share button. But be careful not to trigger the prompt without user action — that would be blocked.