|
| 1 | +--- |
| 2 | +title: "Extensions" |
| 3 | +description: "Use browser extensions in Kernel browsers" |
| 4 | +--- |
| 5 | + |
| 6 | +Kernel's browsers support running with custom Chrome extensions. |
| 7 | +Chrome extensions must be unpacked and can be uploaded to Kernel via the CLI or API. |
| 8 | + |
| 9 | +## Uploading extensions |
| 10 | + |
| 11 | +Here is a simple example of an unpacked extension: |
| 12 | + |
| 13 | +<CodeGroup> |
| 14 | +```js ./my-extension/content-script.js |
| 15 | +document.body.innerHTML = document.body.innerHTML.replace(/AI/g, "A1"); |
| 16 | +``` |
| 17 | + |
| 18 | +```json ./my-extension/manifest.json |
| 19 | +{ |
| 20 | + "manifest_version": 3, |
| 21 | + "version": "1.0", |
| 22 | + "name": "AI to A1", |
| 23 | + "description": "Replace AI with A1", |
| 24 | + "content_scripts": [ |
| 25 | + { |
| 26 | + "matches": [ |
| 27 | + "https://*/*" |
| 28 | + ], |
| 29 | + "js": [ |
| 30 | + "content-script.js" |
| 31 | + ] |
| 32 | + } |
| 33 | + ] |
| 34 | +} |
| 35 | +``` |
| 36 | +</CodeGroup> |
| 37 | + |
| 38 | +Once these files are in place, you can upload them to Kernel via the CLI (or [API](/api-reference/extensions/upload-a-browser-extension)): |
| 39 | + |
| 40 | +```bash |
| 41 | +kernel extensions upload ./my-extension --name my-extension |
| 42 | +``` |
| 43 | + |
| 44 | +Extensions uploaded to Kernel are assigned a random ID, but you can also give them a name for easier reference. |
| 45 | +This name must be unique within your organization. |
| 46 | + |
| 47 | +## Using extensions in a browser |
| 48 | + |
| 49 | +Passing the extension name or ID to the `create` method will load it into the browser: |
| 50 | + |
| 51 | +<CodeGroup> |
| 52 | +```typescript Typescript/Javascript |
| 53 | +import { Kernel } from '@onkernel/sdk'; |
| 54 | + |
| 55 | +const kernel = new Kernel(); |
| 56 | +const kernelBrowser = await kernel.browsers.create({ |
| 57 | + extensions: [{ name: "my-extension" }], |
| 58 | +}); |
| 59 | +``` |
| 60 | + |
| 61 | +```python Python |
| 62 | +import kernel |
| 63 | + |
| 64 | +client = kernel.Kernel() |
| 65 | +kernel_browser = client.browsers.create(extensions=[{name: 'my-extension'}]) |
| 66 | +``` |
| 67 | + |
| 68 | +```bash CLI |
| 69 | +kernel browsers create --extension my-extension |
| 70 | +``` |
| 71 | +</CodeGroup> |
| 72 | + |
| 73 | + |
| 74 | +## Using extensions directly from the Chrome Web Store |
| 75 | + |
| 76 | +Kernel's CLI offers a command for fetching and unpacking extensions directly from the Chrome Web Store. |
| 77 | +Simply pass the URL of the extension you want to download and the CLI will download the extension and unpack it into the specified directory. |
| 78 | + |
| 79 | +```bash CLI |
| 80 | +kernel extensions download-web-store https://chromewebstore.google.com/detail/shutterfly-address-book-e/lddlpciejomhjehckimopnomegilaocb --to ./downloaded-extension |
| 81 | +``` |
| 82 | + |
| 83 | +From here you can upload the extension to Kernel as normal. |
| 84 | + |
| 85 | +```bash CLI |
| 86 | +kernel extensions upload ./downloaded-extension --name my-extension |
| 87 | +``` |
| 88 | + |
| 89 | +## Loading an extension into a running browser |
| 90 | + |
| 91 | +If you have a browser running and would like to load an extension into it after the browser session has started, Kernel also allows you to do that via the CLI (or [API](http://localhost:3000/api-reference/browsers/ad-hoc-upload-one-or-more-unpacked-extensions-to-a-running-browser-instance)): |
| 92 | + |
| 93 | +```bash CLI |
| 94 | +kernel browsers extensions upload <session_id> ./my-extension |
| 95 | +``` |
| 96 | + |
| 97 | +<Info> |
| 98 | +Note that this will restart the browser process and break any connections to the browser CDP URL. |
| 99 | +</Info> |
0 commit comments