Turns out the x-devonthink://createwebdocument approach works great when you pass in source:
(function() {
if (navigator.appVersion.indexOf("Mac") >= 0) {
var url =
'x-devonthink://createWebarchive?title=' + encodeURIComponent(document.title) +
'&location=' + encodeURIComponent(window.location) +
'&referrer=' + encodeURIComponent(document.referrer) +
'&width=' + window.innerWidth +
'&encoding=' + document.characterSet;
var isChrome = (navigator.appVersion.indexOf("Chrome") >= 0);
var source = encodeURIComponent(document.documentElement.outerHTML);
if (!isChrome || (url.length + source.length) < 2097152) {
url += '&source=' + source;
}
window.location.href = url; // Changed from 'window.document.location' for clarity
} else {
console.log("The Clip to DEVONthink extension only works on a Mac.");
}
})();
var activate = function()
{
chrome.tabs.executeScript(null, {file:"activate.js"});
}
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status === 'complete' && tab.active) {
chrome.tabs.executeScript(tabId, {file: "activate.js"});
}
});
// The rest of your existing main.js code...
// Existing activate function and other code...
chrome.browserAction.onClicked.addListener(function (tab)
{
activate();
});
chrome.commands.onCommand.addListener(function(command)
{
if (command == 'activate')
{
activate();
}
});
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse)
{
if (request.action == "devonthink_activate")
{
activate();
}
});
```manifest.json
{
"background": {
"scripts": ["main.js"]
},
"content_security_policy": "script-src 'self'; object-src 'self'",
"description": "Modified script.",
"permissions": [
"tabs",
"<all_urls>"
],
...}
The only issue is that it brings up Devonthink each time. I’m guessing that’s just in the nature of such URL schemes. If anyone has any clever ideas for how I can automate creating and saving webarchive files into Devonthink whenever i load a page, I’d appreciate it.