-
-
Notifications
You must be signed in to change notification settings - Fork 287
Inject into other extensions
(This page is only for advanced users)
Vimium C is carefully designed and provides a convenient injector to run onto pages of another extension, as soon as the extension declares that itself has Vimium C supports.
So here's a tutorial about how to create such an extension (e.g. the official PDF Viewer).
- Install Vimium C and PDF Viewer on your browser
- Go to Chrome's
User Datafolder, which may be "C:\Users\<your username>\AppData\Local\Google\Chrome\User Data" on Windows - search the folder "Default" for a folder named "oemmndcbldboiebfnladdacbdfmadadm", copy it's subfolder (e.g. named "2.0.673_0") to somewhere others for further work
- search the folder for
.htmland.htmlfiles (e.g.content/web/viewer.html) - and open them using a good text editor / IDE (like Notepad++ and Visual Studio Code)
- find "
</head>", and if the text doesn't exist, find "</body>" or even "</html>" - insert a line of
<script type="text/javascript" src="chrome-extension://hfjbmagddngcpeloejdejnfgbamkjaeg/lib/injector.js"></script>before the found position
- if Vimium C has a different ID (the options page is not chrome-extension://hfjbmagddngcpeloejdejnfgbamkjaeg/pages/options.html)
- you will need to modify the URL above and replace the URL's origin part.
- repeat the step above on all HTML files, and save all changes
- open
manifest.jsonusing your text editor - find the line containing "
content_security_policy", and insert "chrome-extension://hfjbmagddngcpeloejdejnfgbamkjaeg/" (note the beginning space character) between "script-src ..." and the next ";" - if there's no such a line containing "
content_security_policy", then just insert a line of"content_security_policy": "script-src 'self' chrome-extension://hfjbmagddngcpeloejdejnfgbamkjaeg/; object-src 'self'",after the first "{" character - the CSP rule above is required since Chrome 56, or external scripts wouldn't run on injected extensions
- delete a line looking like
"key": "...",(to avoid ID conflicts with the original extension) - save
manifest.json - delete the folder
_metadatabecause now the folder cann't pass Chrome's file content verification
- open
chrome://extension, and click the switcher of "Developer mode" (in Chinese, it's "开发者模式") - click the newly visible button "
Load unpacked extension..." and choose the work folder to load it as an extension - now Chrome will assign a new unique ID for the new extension, which is shown on chrome://extension,
and remember it (e.g. "
nacjakoppgmdcpemlfnfegmlhipddanj") - go to the Vimium C Options page, in advanced options add the ID into the "White list of other extension IDs", and then save changes
- open pages of the new extension and now Vimium C should work perfectly.
- if the modified extension is PDF Viewer, then just open a PDF file and Vimium C will be able to mark most buttons
Firefox generates a different UUID for the same extension everytime you install it, making the URL of "injector.js" is uncertain. Therefore, Vimium C puts its UUID into the response for message "99" on Firefox since version 1.74.
browser.runtime.sendMessage('vimium-c@gdh1995.cn', { handler: 99 }).then(res => {
const { host } = res;
console.log(host); // for example, log "d1ba02e9-ec90-46dc-8623-69e15961cc86"
// localStorage.vimiumHost = host; // may cache it for further usages
const injector = `moz-extension://${host}/lib/injector.js`;
const script = document.createElement('script');
script.src = injector;
document.head.appendChild(script);
});The key changes are: <script> in HTML files, changing CSP and removing "key": line in manifest.json, and add wanted extension IDs into Vimium C's white list for injection.
Usually Vimium C works perfectly on extension environments, but if any bug or crash is found, please file an issue on https://github.com/gdh1995/vimium-c/issues . Thanks for your help.
For example, a modified viewer.html from PDF Viewer looks like:

And a modified manifest.json from X New Tab looks like:
