Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monkey-patching browser APIs with ZeroFrame #141

Open
filips123 opened this issue Mar 28, 2020 · 2 comments
Open

Monkey-patching browser APIs with ZeroFrame #141

filips123 opened this issue Mar 28, 2020 · 2 comments

Comments

@filips123
Copy link
Contributor

ZeroFrame currently monkey-patches AJAX browser APIs to add AJAX key. It would also be good to monkey-patch some other browser APIs, like localStorage or history, to call ZeroFrame's wrapper actions instead of directly browser APIs. This would make it possible to use some third-party libraries (like JS routers which use History API, maybe some storage helpers) with ZeroNet without any modifications to them (this currently requires to modify them to use ZeroFrame instead of browser APIs).

Some of APIs which should be monkey-patched are:

  • localStorage: Use wrapper's wrapperGetLocalStorage and wrapperSetLocalStorage. However, I don't know if this is possible because browsers prevent accessing and modifying localStorage object in iframe sandbox.

  • History: Use wrapperGetState, wrapperPushState, wrapperReplaceState and correctly handle URL rewrites in other History's objects. This would be easier because you can access them inside sandbox, but they just don't do anything.

  • As well as some other wrapper actions like wrapperOpenWindow and wrapperSetTitle.

@filips123
Copy link
Contributor Author

@HelloZeroNet Would it be possible to implement this, at least support for History API? I think that this would be quite useful, as it would enable you to use third-party JavaScript router libraries that currently don't work with ZeroNet.

But apart from just handling APIs, there should probably also be some good way of handling ? that is prepended to paths which won't mess up with libraries?

@HelloZeroNet
Copy link
Owner

After some quick test it's possible to override window.history functions, but not the window.history object

So it could be possible, but I'm not sure if it will be compatible with every router as they could use window.location which is afaik not possible to override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants