Closed longbui-novobi closed 1 year ago
Hello @longbui-novobi and thank you for your enthusiasm!
Ouch, I didn't know that browser extensions have an increased security/more restricted environment. This will be an issue for me as well, because I planned to make some owl dev tools extension in the future.
Well, I can explain why the new Function(...)
call is necessary: it is because Owl compile templates at runtime, so it needs to create the function that will render each template. For now, there is no way around.
But in many cases, runtime compilation is not necessary, since the templates are known ahead of time. So, what we need is to split the owl-template-compiler
(template compiler code + xml helper) and the owl-runtime
code (everything else). The good news is that the compiler code is actually 30/40% of the codebase, so the runtime code will be much smaller.
But then, to be able to use the runtime code, we need some way of compiling templates ahead of time. That should be pretty easy, since it is basically a call to the compile function, then generate some js file with the template code.
So, to conclude this message, what you need is sadly not possible for now, but it should not be hard to make some progress in that direction. I'll see if I can do something.
@longbui-novobi I made a PR to add basic support for compiling templates ahead of time, and to support building owl without the template compiler: https://github.com/odoo/owl/pull/1196/files (hopefully, it will be merged sometimes next week)
There are some notes on how to do that: see commit https://github.com/odoo/owl/pull/1196/commits/d2c68935666610549570c71c4c54a99dea7d23e3 But clearly, the tooling is quite rough yet. I can't commit much more time to that for now, because it is not a focus point for Odoo. But I expect the situation to improve in the future. In the meantime, it is now possible. If you have some comment/feedback on this, I'll be happy to see what we can do to make this simpler.
The compilation of the templates ahead of time works well but is still slow to use: it is not possible to define a destination path for the templates.js file.
While there is still some work to be done to make the tooling easier to use, this is now possible (and we are currently writing the owl devtools extension as an owl application). Do open new issues with regards to the quality of the tooling surrounding AoT template compilation if you have some specific painpoints you would like to be addressed.
I am so excited to use OWL to build a Chrome Extension. But in the OWL Library, we have to call a new Function(...) at line 4903 to execute some script. Unfortunately, that's determined unsafe-eval. How can I bypass that?