This question has been flagged
2 Replies
4076 Views

I am using Odoo 14 (Enterprise Edition). I have been customizing my website's javascript through the JS Editor in the Customize tab in the Website App. The last time I updated the custom js file, I left in a syntax error. This of course cancels all the javascript in the file, but it also seems to break all other js functionality, which means I can no longer access the JS Editor to fix the syntax error. Is there another way to edit the js file? If not, what can I do?

Avatar
Discard

Sorry for using the answer to comment, but I've just created this account and I can't comment yet.


I've run into the same problem and I was wondering if you've managed to find a solution?

Best Answer

I had to override the offending javascript file through Chrome's dev tools:

1. In Chrome, open Dev Tools (F12 or Right-click > Inspect)

2. Select the "Sources" tab> "Overrides"

3. Create a new folder on your desktop (or wherever) with whatever name you want (to store your override files).

4. Click "Select folder for overrides" at the top of the left-most column.

5. Select the folder you created in Step 3.

6. Click "Allow" at the top when it pops up.

7. Click "Enable Local Overrides" at the top of the left-most column (if unchecked).

8. With dev tools open, refresh your Odoo website page.

9. Go to the Chrome Dev Tools "Console" tab.

10. Click the link to the offending javascript_file.js:line_number at the top right of the Console error message.  This will take you directly to the offending javascript code within the offending javascript file.

NOTE: If there is no explicit error in the Console with a link to the offending Javascript file...As of Odoo 15 (at least for me), your custom code (aka the offending javascript file) resides in /MyHostName.odoo.com/web/assets/debug/3/web.assets_frontend_lazy.js . You can download this file from the "Page" tab in Chrome Dev Tools and place it in your override folder you created in Step 3, placing it in the same exact filepath indicated under the "Page" tab (which is presumably similar/the same to the filepath I just indicated).

11. Delete the offending code, then save (ctrl+S). This saves the modified .js file to your override folder you made in Step 3.

12. Now refresh the Odoo website page. It will load your modified .js file from the folder on your PC, instead of the broken one.

13. If you carefully deleted the offending javascript code in Step 11, you should now be able to use Odoo Javascript features again (most importantly, you should now be able to open the HTML/CSS/Javascript Editor again to delete the offending javascript code once and for all...AND SAVE IT.)

14. After deleting the offending code from Odoo's built-in editor & saving, confirm your pesky javascript is truly gone: Disable the "Allow overrides" checkbox in the dev console, and refresh the page (or open the site in an Incognito tab).


Odoo should definitely consider putting your custom javascript into a separate .js file instead of baking it into a huge other one (so you can just temporarily disable the entire script file with uBlock Origin/AdBlock Plus). Even better yet, make it so their website's javascript doesn't break (try{}catch{}?) if there's syntax errors in your own code.

Avatar
Discard

you are a life savior

well done, that was very insightful.

The best explanation I have ever found on forum for such a problem.

Author Best Answer

Yes! I found the following solution. If you go to Settings and activate Developer mode (with assets) it seems to block the custom javascript but not the native one, allowing you to open the custom javascript editor and fix the error.

Avatar
Discard

Not working for me :( It's ridiculous that you can't edit the javascript file another way, in case you break the entire website with an accidental bug!