MCPcopy
hub / github.com/SeleniumHQ/selenium / installExtension

Function installExtension

javascript/selenium-webdriver/firefox.js:147–182  ·  view source on GitHub ↗

* Installs an extension to the given directory. * @param {string} extension Path to the xpi extension file to install. * @param {string} dir Path to the directory to install the extension in. * @return {!Promise } A promise for the add-on ID once * installed.

(extension, dir)

Source from the content-addressed store, hash-verified

145 * installed.
146 */
147async function installExtension(extension, dir) {
148 const ext = extension.slice(-4)
149 if (ext !== '.xpi' && ext !== '.zip') {
150 throw Error('File name does not end in ".zip" or ".xpi": ' + ext)
151 }
152
153 let archive = await zip.load(extension)
154 if (!archive.has('manifest.json')) {
155 throw new AddonFormatError(`Couldn't find manifest.json in ${extension}`)
156 }
157
158 let buf = await archive.getFile('manifest.json')
159 let parsedJSON = JSON.parse(buf.toString('utf8'))
160
161 let { browser_specific_settings } =
162 /** @type {{browser_specific_settings:{gecko:{id:string}}}} */
163 parsedJSON
164
165 if (browser_specific_settings && browser_specific_settings.gecko) {
166 /* browser_specific_settings is an alternative to applications
167 * It is meant to facilitate cross-browser plugins since Firefox48
168 * see https://bugzilla.mozilla.org/show_bug.cgi?id=1262005
169 */
170 parsedJSON.applications = browser_specific_settings
171 }
172
173 let { applications } =
174 /** @type {{applications:{gecko:{id:string}}}} */
175 parsedJSON
176 if (!(applications && applications.gecko && applications.gecko.id)) {
177 throw new AddonFormatError(`Could not find add-on ID for ${extension}`)
178 }
179
180 await io.copy(extension, `${path.join(dir, applications.gecko.id)}.xpi`)
181 return applications.gecko.id
182}
183
184class Profile {
185 constructor() {

Callers 1

buildProfileFunction · 0.85

Calls 8

ErrorFunction · 0.85
getFileMethod · 0.80
joinMethod · 0.80
toStringMethod · 0.65
loadMethod · 0.45
hasMethod · 0.45
parseMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected