Commit d7ff98f
committed
[Win32][Edge] Fix BrowserFunction race condition using AddScriptToExecuteOnDocumentCreated
In Edge/WebView2, execute() is asynchronous. When new BrowserFunction()
is called, the injection script is queued via ExecuteScript(), but if a
page navigation completes before WebView2 processes that queued script,
the function is unavailable in the new document. This race is most
easily triggered when two Browser instances are created in quick
succession.
Fix: override createFunction() to also register the function script via
AddScriptToExecuteOnDocumentCreated. This API guarantees that the script
runs on every future document creation, before any page scripts —
eliminating the race condition. The script ID returned by the async
registration is stored so it can be cleaned up via
RemoveScriptToExecuteOnDocumentCreated when the BrowserFunction is
disposed.
Functions registered via AddScriptToExecuteOnDocumentCreated are
excluded from the NavigationStarting re-injection path to avoid
redundant double-injection. Only functions created inside a WebView2
callback (inCallback > 0) — where the persistent registration is
skipped to avoid a deadlock — still rely on the NavigationStarting
fallback.
When createFunction() is called from within a WebView2 callback
(inCallback > 0), blocking on the registration callback would deadlock,
so the persistent registration is skipped and the existing
NavigationStarting re-injection remains as a fallback.
Fixes #201 parent 9b0b255 commit d7ff98f
3 files changed
Lines changed: 139 additions & 3 deletions
File tree
- bundles/org.eclipse.swt
- Eclipse SWT Browser/win32/org/eclipse/swt/browser
- Eclipse SWT PI/win32/org/eclipse/swt/internal/ole/win32
- tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit
Lines changed: 46 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
| |||
1146 | 1148 | | |
1147 | 1149 | | |
1148 | 1150 | | |
1149 | | - | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
1150 | 1156 | | |
1151 | 1157 | | |
1152 | 1158 | | |
1153 | | - | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
1154 | 1165 | | |
1155 | | - | |
1156 | 1166 | | |
1157 | 1167 | | |
1158 | 1168 | | |
| |||
1836 | 1846 | | |
1837 | 1847 | | |
1838 | 1848 | | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
1839 | 1882 | | |
bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/ole/win32/ICoreWebView2.java
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
| |||
Lines changed: 89 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2943 | 2943 | | |
2944 | 2944 | | |
2945 | 2945 | | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
| 2993 | + | |
| 2994 | + | |
| 2995 | + | |
| 2996 | + | |
| 2997 | + | |
| 2998 | + | |
| 2999 | + | |
| 3000 | + | |
| 3001 | + | |
| 3002 | + | |
| 3003 | + | |
| 3004 | + | |
| 3005 | + | |
| 3006 | + | |
| 3007 | + | |
| 3008 | + | |
| 3009 | + | |
| 3010 | + | |
| 3011 | + | |
| 3012 | + | |
| 3013 | + | |
| 3014 | + | |
| 3015 | + | |
| 3016 | + | |
| 3017 | + | |
| 3018 | + | |
| 3019 | + | |
| 3020 | + | |
| 3021 | + | |
| 3022 | + | |
| 3023 | + | |
| 3024 | + | |
| 3025 | + | |
| 3026 | + | |
| 3027 | + | |
| 3028 | + | |
| 3029 | + | |
| 3030 | + | |
| 3031 | + | |
| 3032 | + | |
| 3033 | + | |
| 3034 | + | |
2946 | 3035 | | |
2947 | 3036 | | |
2948 | 3037 | | |
| |||
0 commit comments