Comments (15)
Actually JavaScript code in content-script.js
does have access to the page -exactly same as Firefox. So by logical reasoning, it ought to work in the same way in both browsers.
from timimi.
Here's the problem: in Firefox
- content-script.js injects patch-classic-io.js into the page
- patch-classic-io.js modifies
window.mozillaLoadFile
and others;
in Chrome patch-classic-io.js is injected, but it gets a sandboxed context and window
is not the same as window
, so the change that patch-classic-io.js introduces doesn't really affect window.mozillaLoadFile
etc of the page itself. That answer at SO suggests a hack that can help though. I'll probably give it a try soon; this will make the code ugly though because the whole patch-classic-io.js should be put as a JS string inside content-script.js.
from timimi.
What if we add the code in the patch to the content-script itself - as a function? Instead of inject, we can call it as a function, right?
from timimi.
Not sure, could you provide a sample code?
The following seems to work:
-
change
injectExtensionScript
to this:function injectExtensionScript(text) { const scriptElement = document.createElement("script"); scriptElement.innerHTML = text; document.head.appendChild(scriptElement); scriptElement.remove(); }
-
call it (instead of
injectExtensionScript('patch-classic.io)
) like this:
injectExtensionScript(`
window.mozillaLoadFile = function(path) {
try {
// Just read the file synchronously
var xhReq = new XMLHttpRequest();
xhReq.open("GET", "file:///" + encodeURIComponent(path), false);
xhReq.send(null);
return xhReq.responseText;
} catch(ex) {
return false;
}
};
window.mozillaSaveFile = function(path, content) {
var messageBox = document.getElementById("tiddlyfox-message-box");
if(!messageBox) return false;
// Create the message element and put it into the message box
var message = document.createElement("div");
message.setAttribute("data-tiddlyfox-path", path);
message.setAttribute("data-tiddlyfox-content", content);
messageBox.appendChild(message);
// Create and dispatch the custom event to the extension
var event = document.createEvent("Events");
event.initEvent("tiddlyfox-save-file", true, false);
message.dispatchEvent(event);
return true;
};
// expose the supported I/O events
window.eventBasedIO = {
save: {
name: 'tiddlyfox-save-file'
},
saved: {
name: 'tiddlyfox-have-saved-file'
}
};`);
(sorry for ugly formatting, github markup makes it a bit difficult)
However, while this injecting works in extension edited locally, it doesn't seem to find the Timimi backend, so I've only succeeded with saving when activated both current Timimi extension and my local version. Any idea how can I fix this?
from timimi.
You mean you want to create a local environment for testing purposes?
from timimi.
Yes, that would be helpful (so that I can create PRs with more confidence)
from timimi.
Actually, that worked in Firefox: I loaded Timimi extension from cloned and edited repo on local file system and it interacted with Timimi backend just like the main extension. Not sure why this is not the case in Chrome (well, in Vivaldi, I haven't tested this in Chrome yet)
from timimi.
Yeah. Chrome works a little differently. You need to edit the timimi.json for it to work with chrome in testing environment.
from timimi.
Here is what you have to do.
Uninstall timimi that you may have installed from chrome webstore
Load the unpacked extension to Chrome.
In the extension page, timimi will have an extension id. Copy that.
Now go to timimi.json and replace the extension id in that with the value you copied
from timimi.
well, this doesn't seem to be working. To be sure, I've retested in Chrome (instead of Vivaldi), but it's the same:
- I have installed the unpacked extension
- copied the id, opened
<user folder>\AppData\Roaming\Timimi-Chrome\Timimi.json
(is it the one?), changedallowed_origins
by substituting the id - opened TWC 2.9.2, checked that the script is injected (
mozillaSaveFile
changed etc), added some changes, (unchecked saving backups,) called saving
A message (more likely browser than native, white one with Timimi icon) appeared saying "Timimi save FAILED Error on contacting Timimi host" and the changes are not saved. I'll probably create a PR in parallel (not sure where the changes should go though: they can be used for Firefox too and it's not nice if the code is duplicated anyway, since further changes should be remembered to be put into both)
from timimi.
Hi Riz, any comments on this? What do you think about merging #48 so that we can use this minimal implementation in the next release and improve it further if needed?
from timimi.
Merged. Now the only thing we have to see is if it passes the chrome store's security check.
from timimi.
Great, thanks! Yeah, the security check is indeed is an interesting question because such code injection may be considered "hacky".
By the way, do you have any plans to de-duplicate code for Firefox and Chrome extensions? Like generate one from another, so that it is enough to introduce new changes only in one place.
from timimi.
The plan is to make the code similar in both eventually.
from timimi.
Hi Riz,
we have to see is if it passes the chrome store's security check
any news on this? What's the usual time they take to review an updated version?
from timimi.
Related Issues (20)
- VirusTotal shows backend as malicious HOT 2
- Prompt to reinstall back-end on every Firefox update HOT 1
- Could tiddlers.json would be exported automatically when saved and use the same backup copies strategy as the wiki? HOT 3
- 'timimi-2-1-1-Mac' File Not Opening On MacOS HOT 2
- Timimi save FAILED on Linux/firefox (due to Snap package of Firefox being installed in Ubuntu 21.10) HOT 8
- Serious error with Timimi HOT 1
- Newer MAC with M1 processor is not supported HOT 2
- timimi failed to save tiddlywiki with firefox snap version 101 HOT 7
- how to build on arm linux? HOT 4
- please update the timimi HOT 6
- Tiddlywiki not saving on Debian + Firefox HOT 2
- timimi-2-1-1-Mac seems to be not an executable file HOT 3
- Error: attempt to postMessage on disconnected port.'
- Maybe some kind of error message if the saver is not installed? HOT 1
- TWiki saves correctly, but pops an error message
- support for feather wiki
- Timimi stopped saving on Windows Firefox
- Save failed, Error: an unexpected error occured (Firefox 118, Ubuntu 22.04) HOT 3
- Hi! I need help / support on CleverNote(Timimi Docs) theme! HOT 1
- Timimi extension not getting access to local TiddlyWiki (macOS Sonoma; Apple Silicon; Chrome 120.0.6099.129) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from timimi.