Created
April 18, 2025 18:05
-
-
Save alexnj/eae16e75795c86eb8800b3888225aaa1 to your computer and use it in GitHub Desktop.
Chrome Extension Targets introspection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Chrome extension window</title> | |
</head> | |
<body> | |
<h1>Hello from Chrome extension</h1> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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