| title | Sample: Picture viewer pop-up webpage |
|---|---|
| description | An extension that displays an image file in a webpage in a pop-up, without JavaScript. |
| author | MSEdgeTeam |
| ms.author | msedgedevrel |
| ms.topic | article |
| ms.service | microsoft-edge |
| ms.subservice | extensions |
| ms.date | 01/16/2025 |
This sample is a browser extension, without JavaScript, that displays the stars.jpeg image in a small webpage in a pop-up in any Microsoft Edge tab:
You can use various tools to clone a GitHub repo. You can download a selected directory, or clone the entire repo.
Clone the MicrosoftEdge-Extensions repo to your local drive, and then switch to a working branch, as follows.
-
In a command prompt, enter
gitto check whether git is installed. -
If not done yet, download git and install it.
-
If not done yet, start a command prompt where git is installed.
-
Change to the directory where you want to clone the MicrosoftEdge-Extensions repo to. For example:
cd C:/Users/localAccount/GitHub/ -
In Microsoft Edge, go to the MicrosoftEdge-Extensions repo.
-
Click the down-arrow on the right side of the green Code button, and then in the Clone using the web URL section, click the Copy url to clipboard button next to
https://github.com/microsoft/MicrosoftEdge-Extensions.git. -
In the command prompt window, enter the command:
git clone https://github.com/microsoft/MicrosoftEdge-Extensions.git
The
/MicrosoftEdge-Extensions/directory is added within the directory that you specified.
-
Check the list of directories:
lsThe
/MicrosoftEdge-Extensions/directory is listed. -
Switch to the new directory:
cd MicrosoftEdge-Extensions -
Create a working branch:
git branch test -
Switch to the working branch:
git switch testReturns:
Switched to branch 'test'
You are now free to modify the code in your working branch, without altering the code that's in the "main" branch of the repo. Later you might want to switch back to the "main" branch, or create a different branch based off the "main" branch.
-
If not done already, install GitHub desktop: go to https://github.com/apps/desktop, and then click the Download now button.
-
Go to the MicrosoftEdge-Extensions repo.
-
Click the Code button, and then select Open with GitHub Desktop.
A dialog opens, saying This site is trying to open GitHubDesktop.exe.
-
Click the Open button.
GitHub Desktop opens, with the MicrosoftEdge-Extensions repo selected in the upper left dropdown list.
Or, in GitHub Desktop, the Clone a repository dialog opens:
-
Specify the local drive path to place the cloned repo directory into; for example:
C:\Users\accountname\GitHub\. -
Click the Clone button.
-
In GitHub Desktop, make sure that in the upper left of GitHub desktop, Current repository is MicrosoftEdge-Extensions.
In the Current branch drop-down list, it says main.
-
In the Current branch drop-down list, click the Branches tab, and then click the New branch button.
The Create a branch dialog opens.
-
In the Name text box, enter a branch name, such as test, and then click the Create branch button.
In the upper middle and lower left of GitHub Desktop, the current branch is shown, such as test.
You are now free to modify the code in your working branch, without altering the code that's in the "main" branch of the repo. Later you might want to switch back to the "main" branch, or create a different branch based off the "main" branch.
Instead of installing the sample from Microsoft Edge Add-ons, you'll install the sample locally, so that you can possibly modify it and quickly test the changes. Installing locally is sometimes called sideloading an extension.
-
In Microsoft Edge, click the Extensions (
) button, next to the Address bar, if this icon is displayed. Or, select Settings and more (
) > Extensions. The Extensions pop-up opens: -
Click Manage extensions. The Extensions management page opens in a new tab:
-
Turn on the Developer mode toggle.
-
When installing your extension for the first time, click the Load unpacked (
) button. The Select the extension directory dialog opens. -
Select the directory that contains the extension's source files, such as
manifest.json.Example path:
C:\Users\localAccount\GitHub\MicrosoftEdge-Extensions\Extension-samples\picture-viewer-popup-webpage -
Click the Select Folder button.
The Select the extension directory dialog closes.
The extension is installed in the browser, similar to an extension that's installed from Microsoft Edge Add-ons:
-
Go to a webpage, such as TODO app, in a new window or tab. For this sample, this step is optional and is just to match the screenshots; this sample doesn't require a webpage to be open.
-
Refresh the webpage. This is sometimes required after reloading an extension.
-
In Microsoft Edge to the right of the Address bar, if this icon is displayed, click the Extensions (
) button. Or, select Settings and more (
) > Extensions.The Extensions pop-up opens:
-
Click the extension's icon or name (Picture viewer pop-up webpage).
The extension opens, and the extension's icon is added next to the Address bar and Extensions (
) icon. The extension displays popup.html, containingstars.jpeg, in a pop-up: -
Click the extension's button next to the Address bar. The pop-up window closes.
See also:
In the following sections, you study the sample. After that, to develop your own Microsoft Edge extension, you can copy and modify the sample's directory, and install and test the resulting extension.
The sample has the following directory structure:
Example path for the sample:
C:\Users\localAccount\GitHub\MicrosoftEdge-Extensions\Extension-samples\picture-viewer-popup-webpage
Directories and files in the /picture-viewer-popup-webpage/ directory:
/icons/
extension-icon16x16.png
extension-icon32x32.png
extension-icon48x48.png
extension-icon128x128.png
/images/
stars.jpeg
/popup/
popup.html
manifest.json
- The
/icons/directory contains versions of a.pngfile that's used to represent the extension near the browser's Address bar. - The
/images/directory containsstars.jpeg, which is displayed in the extension's pop-up. - The
/popup/directory containspopup.html, which defines the webpage content that's displayed in the extension's pop-up. manifest.jsoncontains basic information about the extension.
Every extension package must have a manifest.json file at the root. The manifest provides details of your extension, the extension package version, and the extension name and description.
manifest.json contains the following lines:
{
"name": "Picture viewer pop-up webpage",
"version": "0.0.0.1",
"manifest_version": 3,
"description": "A browser extension that displays an image in a pop-up webpage.",
"icons": {
"16": "icons/extension-icon16x16.png",
"32": "icons/extension-icon32x32.png",
"48": "icons/extension-icon48x48.png",
"128": "icons/extension-icon128x128.png"
},
"action": {
"default_popup": "popup/popup.html"
}
}The /icons/ directory contains the icon image files. The icons are used as the background image for the button that you click to launch the extension:
When the extension is running, one of the icons is displayed on the toolbar, next to the Address bar:
To close the extension, click the extension's icon on the toolbar, or click the Extensions (
) button.
Recommendations for icons:
- Use
PNGformat, but you can also useBMP,GIF,ICOorJPEGformats. - If you provide a single icon file, use 128 x 128 px, which can be resized by the browser if necessary.
popup.html in the /popup/ directory runs when you launch the extension. When you click the icon to launch the extension, this file is displayed as a modal dialog.
popup.html contains the following code, to display a title and the stars image:
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Picture viewer pop-up webpage</title>
</head>
<body>
<div>
<img src="/images/stars.jpeg" alt="Stars" />
</div>
</body>
</html>The pop-up webpage (popup.html) is registered as the "default_popup" in manifest.json, in the action key section:
manifest.json (portion)
{
"action": {
"default_popup": "popup/popup.html"
}
}To develop your own Microsoft Edge extension, you can copy and modify the sample's directory, and install and test the resulting extension.
After running and testing this extension sample, you can continue on to Sample: Picture inserter using content script, which dynamically inserts JavaScript running as content in the browser tab.
- Sideload an extension to install and test it locally
- Sample: Picture inserter using content script
- Samples for Microsoft Edge extensions
GitHub:
- MicrosoftEdge-Extensions repo.
- /picture-viewer-popup-webpage/ - source code of this sample.





