MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / asBase64

Function asBase64

javascript/selenium-webdriver/lib/web_extension.js:218–226  ·  view source on GitHub ↗

* `value` itself, if it is base64 of a packed extension. Checking the decoded bytes, not just the * alphabet, matters: a mistyped relative path such as `extensions/myext` is valid base64 too, and * sending it would surface as an unrelated error from the browser. * @param {string} value * @return

(value)

Source from the content-addressed store, hash-verified

216 * @throws {error.InvalidArgumentError} if it is neither.
217 */
218function asBase64(value) {
219 const bytes = /^[A-Za-z0-9+/]+={0,2}$/.test(value) ? Buffer.from(value, 'base64') : null
220 if (!bytes || !ARCHIVE_SIGNATURES.some((signature) => bytes.subarray(0, signature.length).equals(signature))) {
221 throw new error.InvalidArgumentError(
222 `No such file or directory, and not base64 of a packed extension (.xpi/.zip/.crx): ${truncate(value)}`,
223 )
224 }
225 return value
226}
227
228function truncate(value, max = 80) {
229 return value.length > max ? `${value.slice(0, max)}...` : value

Callers 1

encodeExtensionFunction · 0.85

Calls 4

truncateFunction · 0.85
testMethod · 0.45
fromMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected