Page 1 of 2

Sandbox not allowing injecting JS code?

PostPosted: Thu Aug 05, 2021 4:17 am
by ajitchavan
While sandbox is enabled, injecting javascript code using ExecuteJavaScript() getting an error at first line of JS code.

[0804/090146.960527:WARNING:display_handler_impl.cc(107)] [JS][https://www.google.com/?gws_rd=ssl](1)Uncaught SyntaxError: Unexpected end of input

If we use --no sandbox flag we do not get any error and can browse.

Re: Sandbox not allowing injecting JS code?

PostPosted: Thu Aug 05, 2021 9:54 am
by magreenblatt
What OS and CEF version? What URL have you loaded, what JS code are you injecting, and triggered by what method or action?

Re: Sandbox not allowing injecting JS code?

PostPosted: Fri Aug 06, 2021 12:11 am
by ajitchavan
Hi Magreenblatt,
Below are the details,
1] OS: "Ubuntu 20.04.2 LTS" server
2] CEF_VERSION: "89.0.18+gb36241d+chromium-89.0.4389.114"
3] JS code: we are adding code to parse websites HTML. Also tried with simple console log but it gives error at first line itself.
Code is injected inside OnContextCreated() using frame and context received.
4] Trigger point: We listen to DOMContentLoaded event.

Same code works when we use --no sandbox flag.

Re: Sandbox not allowing injecting JS code?

PostPosted: Fri Aug 06, 2021 11:22 am
by magreenblatt
What is the JS code that’s failing? Have you tried reducing the code to identify the exact failure condition?

Re: Sandbox not allowing injecting JS code?

PostPosted: Fri Aug 06, 2021 11:53 am
by ajitchavan
Yes I tried reducing code and only added console. Even for that getting same error.
And error shows at line number 1 itself.

[0804/090146.960527:WARNING:display_handler_impl.cc(107)] [JS][https://www.google.com/?gws_rd=ssl](1)Uncaught SyntaxError: Unexpected end of input

Re: Sandbox not allowing injecting JS code?

PostPosted: Sun Aug 08, 2021 1:17 pm
by HarmlessDave
What happens if you manually post your javascript into a Google Chrome F12 console window? We inject a few scripts for different purposes at work (but not in sandbox mode), and more than once the problem has been a typo like missing ";" or "}" or other syntax error. You might also need to remove any hard returns from your string.

Re: Sandbox not allowing injecting JS code?

PostPosted: Mon Aug 09, 2021 2:09 am
by ajitchavan
There are no syntax error such as missing or extra ";" or "}" .For us as well scripts work when we run with no sandbox(--no-sandbox). But when we run same js code with sandbox getting an error at first line itself

Re: Sandbox not allowing injecting JS code?

PostPosted: Mon Aug 09, 2021 6:48 am
by Czarek
Any other messages in logs?

Re: Sandbox not allowing injecting JS code?

PostPosted: Wed Aug 11, 2021 12:19 am
by ajitchavan
There are other logs but those are not relevant to this. It is because I am running application as normal user not as root. For sandbox I can not run it with root user.

Code: Select all
[size=85][0802/115406.958164:ERROR:simple_backend_impl.cc(81)] Failed to create directory: /home/code/cache/Code Cache/wasm
[0802/115406.964797:ERROR:disk_cache.cc(184)] Unable to create cache
[0802/115407.007398:ERROR:database.cc(1707)] Cookie sqlite error 14, errno -2: unable to open database file, sql: -- sqlite3_open()
[0802/115407.007568:ERROR:sqlite_persistent_store_backend_base.cc(97)] Unable to open Cookie DB.
[0802/115407.073511:WARNING:render_app.cc(206)] OnBrowserCreated-renderer mirroring
[0802/115407.262980:WARNING:dom_mirror_js.h(48)] cwd: looking for ext in /extensions/dom_mirroring/
[0802/115407.265028:WARNING:display_handler_impl.cc(107)] [JS][https://www.google.com/?gws_rd=ssl](1)Uncaught SyntaxError: Unexpected end of input
[0802/115407.271337:WARNING:display_handler_impl.cc(107)] [JS][https://www.google.com/?gws_rd=ssl](1)Uncaught SyntaxError: Unexpected end of input
[0802/115407.318766:WARNING:display_handler_impl.cc(107)] [JS][https://www.google.com/?gws_rd=ssl](1)Uncaught SyntaxError: Unexpected end of input[/size]

Re: Sandbox not allowing injecting JS code?

PostPosted: Wed Aug 11, 2021 5:24 am
by Czarek
Does your JS error occur for any injected code? Try some basic code like "void(0)".

The disk errors you have may be relevant.