Android evaluateJavaScript() problem

650 views
Skip to first unread message

Dean Wedel

unread,
Aug 20, 2024, 9:15:07 PMAug 20
to Chromium-dev
In the Android code I'm trying to get Tab.getWebContents().evaluateJavaScript() to work.

Here is what I have:

1. I selected this tab-observer in file src/chrome/browser/tab/java/src/org/chromium/chrome/browser/tab/EmptyTabObserver.java

2. Inside function public void onPageLoadFinished(Tab tab, GURL url) I added this code:
        if (url.getSpec().contains("bing.com"))
        {
            tab.getWebContents().evaluateJavaScript("(function() {" + "  alert('hello!');" + "})()", null);
        }

3. Chromium builds, installs, and runs fine on my Android Pixel. However when I navigate to bing to test this the app just crashes. This confirms that the code IS getting hit but what do I have wrong?

Dean Wedel

unread,
Aug 20, 2024, 9:17:49 PMAug 20
to Chromium-dev, Dean Wedel
I should add that the project runs fine in that I can navigate to other webpages without any problems or crashes.

On bing it properly loads/displays the page and THEN it crashes. . . .

Dean Wedel

unread,
Aug 20, 2024, 9:24:33 PMAug 20
to Chromium-dev, Dean Wedel
This is Chromium code base v128.0.6547.0

Dean Wedel

unread,
Aug 23, 2024, 10:45:42 AMAug 23
to Chromium-dev, Dean Wedel
I also tried evaluating this JavaScript statement but it also just crashes:
> "history.back()"

Any ideas or advice?

Dean Wedel

unread,
Sep 2, 2024, 9:16:09 PMSep 2
to Chromium-dev, Dean Wedel
As an experiment I've moved my code over to file:
> chrome/android/java/src/org/chromium/chrome/browser/app/ChromeActivity.java

The modification looks like this:
>                     public void onPageLoadFinished(Tab tab, GURL url) {
>+                        if (url.getSpec().contains("bing.com"))
>+                        {
>+                            tab.getWebContents().evaluateJavaScript("(function() {" + "  alert('hi!');" + "})()", null);
>+                        }
>                         postDeferredStartupIfNeeded();
>                         OfflinePageUtils.showOfflineSnackbarIfNecessary(tab);
>                     }

But the app just crashes on my Pixel when I visit "bing". . . All other webpages work fine.

Anybody have any ideas what I'm doing wrong?

Dean Wedel

unread,
Sep 5, 2024, 10:06:01 AMSep 5
to Chromium-dev, Dean Wedel
It looks like in file: content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java
For the implementation of "public void evaluateJavaScript(String script, JavaScriptCallback callback) {"
That the first statement is:
> ThreadUtils.assertOnUiThread();

I tried commenting-out that line but my JavaScript call still doesn't work ~ it just crashes.

uazo

unread,
Sep 6, 2024, 2:35:44 AMSep 6
to Chromium-dev, Dean Wedel
> Any ideas or advice?

the only way to figure out why is to check the crash log.

Dean Wedel

unread,
Sep 6, 2024, 8:40:15 PMSep 6
to Chromium-dev, uazo, Dean Wedel
uazo,

Good suggestion. I've sifted through the crash-log and I haven't been able to determine what goes wrong.

Here is a condensed version if you cared to take a look.

Thanks in advance,
Dean
crashlog01-2024-09-06-15-08-30_condensed.txt

uazo

unread,
Sep 9, 2024, 11:16:04 AMSep 9
to Chromium-dev, Dean Wedel, uazo
you have to give it to "third_party/android_platform/development/scripts/stack"
for example:

third_party/android_platform/development/scripts/stack --output-directory out/x64/ ../../$TOMBSTONE >../../$TOMBSTONE.txt

Reply all
Reply to author
Forward
0 new messages