Skip to content

Instantly share code, notes, and snippets.

@alexnj
Created April 18, 2025 18:05
Show Gist options
  • Save alexnj/eae16e75795c86eb8800b3888225aaa1 to your computer and use it in GitHub Desktop.
Save alexnj/eae16e75795c86eb8800b3888225aaa1 to your computer and use it in GitHub Desktop.
Chrome Extension Targets introspection
/**
* background.js
*
* This script runs in the background and listens for the Chrome startup event.
* When Chrome starts, it creates a new popup window displaying popup.html.
*/
chrome.runtime.onStartup.addListener(() => {
openPopupWindow();
});
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === "install") {
openPopupWindow();
}
});
function openPopupWindow() {
chrome.windows.create({
url: 'popup.html',
type: 'popup',
width: 300,
height: 250,
focused: true
}, (window) => {
if (chrome.runtime.lastError) {
console.error("Error creating window:", chrome.runtime.lastError.message);
} else {
console.log("Popup window created successfully:", window);
}
});
}
{
"manifest_version": 3,
"name": "Auto-Open Popup Extension",
"version": "1.0",
"description": "Opens a popup window automatically when Chrome starts.",
"background": {
"service_worker": "background.js"
},
"permissions": [
"windows",
"runtime"
]
}
<html>
<head>
<title>Chrome extension window</title>
</head>
<body>
<h1>Hello from Chrome extension</h1>
</body>
</html>
import { Builder } from 'selenium-webdriver';
import chrome from 'selenium-webdriver/chrome.js';
const chromeBinary = '/path/to/chrome';
const chromeDriverBinary = '/path/to/chromedriver';
let driver = await new Builder()
.forBrowser("chrome")
.setChromeOptions(
new chrome.Options({
'goog:chromeOptions': {
'enableExtensionTargets': true,
}
})
.addArguments([
`load-extension=./test-extension`
])
.setChromeBinaryPath(chromeBinary)
)
.setChromeService(new chrome.ServiceBuilder(chromeDriverBinary))
.build();
try {
await driver.get('https://google.com/');
const handles = await driver.getAllWindowHandles();
console.log('window handles found:', handles);
for (const handle of handles) {
await driver.switchTo().window(handle)
console.log(`${handle}'s title:`, await driver.getTitle());
}
} finally {
await driver.quit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment