Java Code Examples for android.webkit.WebView#setWebContentsDebuggingEnabled()
The following examples show how to use
android.webkit.WebView#setWebContentsDebuggingEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainFragment.java From traccar-manager-android with Apache License 2.0 | 6 votes |
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if ((getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE) != 0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } } getWebView().setWebViewClient(webViewClient); getWebView().setWebChromeClient(webChromeClient); getWebView().addJavascriptInterface(new AppInterface(), "appInterface"); WebSettings webSettings = getWebView().getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setDatabaseEnabled(true); webSettings.setMediaPlaybackRequiresUserGesture(false); String url = PreferenceManager.getDefaultSharedPreferences( getActivity()).getString(MainActivity.PREFERENCE_URL, null); getWebView().loadUrl(url); }
Example 2
Source File: CustomWebViewActivity.java From JsBridge with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle("Custom WebView"); jsBridge = JsBridge.loadModule(); WebView.setWebContentsDebuggingEnabled(true); customWebView = new CustomWebView(this); setContentView(customWebView); customWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); jsBridge.injectJs(customWebView); } }); customWebView.setPromptResult(new PromptResultCallback() { @Override public void onResult(String args, PromptResultImpl promptResult) { jsBridge.callJsPrompt(args, promptResult); } }); customWebView.loadUrl("file:///android_asset/sample.html"); }
Example 3
Source File: ThreadViewFragment.java From something.apk with MIT License | 6 votes |
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface", "NewApi"}) private void initWebview() { threadView.getSettings().setJavaScriptEnabled(true); threadView.setWebChromeClient(chromeClient); threadView.setWebViewClient(webClient); threadView.addJavascriptInterface(new SomeJavascriptInterface(), "listener"); if (Constants.DEBUG && SomeUtils.isKitKat()) { WebView.setWebContentsDebuggingEnabled(true); } if (SomeUtils.isLollipop()) { threadView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } if (SomeUtils.isJellybean()) { threadView.getSettings().setAllowUniversalAccessFromFileURLs(true); threadView.getSettings().setAllowFileAccessFromFileURLs(true); threadView.getSettings().setAllowFileAccess(true); threadView.getSettings().setAllowContentAccess(true); } threadView.setBackgroundColor(SomeTheme.getThemeColor(getActivity(), R.attr.webviewBackgroundColor, Color.BLACK)); registerForContextMenu(threadView); }
Example 4
Source File: Web3View.java From alpha-wallet-android with MIT License | 6 votes |
@SuppressLint("SetJavaScriptEnabled") public void init() { jsInjectorClient = new JsInjectorClient(getContext()); webViewClient = new Web3ViewClient(jsInjectorClient, new UrlHandlerManager()); WebSettings webSettings = getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); webSettings.setDomStorageEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setUserAgentString(webSettings.getUserAgentString() + "AlphaWallet(Platform=Android&AppVersion=" + BuildConfig.VERSION_NAME + ")"); WebView.setWebContentsDebuggingEnabled(true); //so devs can debug their scripts/pages addJavascriptInterface(new SignCallbackJSInterface( this, innerOnSignTransactionListener, innerOnSignMessageListener, innerOnSignPersonalMessageListener, innerOnSignTypedMessageListener), "alpha"); }
Example 5
Source File: SystemWebViewEngine.java From keemob with MIT License | 5 votes |
private void enableRemoteDebugging() { try { WebView.setWebContentsDebuggingEnabled(true); } catch (IllegalArgumentException e) { LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! "); e.printStackTrace(); } }
Example 6
Source File: CordovaWebView.java From IoTgo_Android_App with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private void enableRemoteDebugging() { try { WebView.setWebContentsDebuggingEnabled(true); } catch (IllegalArgumentException e) { Log.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! "); e.printStackTrace(); } }
Example 7
Source File: MainActivity.java From chromium-webview-samples with Apache License 2.0 | 5 votes |
/** * Convenience method to set some generic defaults for a * given WebView * * @param webView */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setUpWebViewDefaults(WebView webView) { WebSettings settings = webView.getSettings(); // Enable Javascript settings.setJavaScriptEnabled(true); // Use WideViewport and Zoom out if there is no viewport defined settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); // Enable pinch to zoom without the zoom buttons settings.setBuiltInZoomControls(true); // Allow use of Local Storage settings.setDomStorageEnabled(true); if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { // Hide the zoom controls for HONEYCOMB+ settings.setDisplayZoomControls(false); } // Enable remote debugging via chrome://inspect if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } webView.setWebViewClient(new WebViewClient()); }
Example 8
Source File: QuickWebView.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 初始化设置 */ public void settingWebView() { WebSettings settings = getSettings(); String ua = settings.getUserAgentString(); // 设置浏览器UA,JS端通过UA判断是否属于Quick环境 settings.setUserAgentString(ua + " QuickHybridJs/" + BuildConfig.VERSION_NAME); // 设置支持JS settings.setJavaScriptEnabled(true); // 设置是否支持meta标签来控制缩放 settings.setUseWideViewPort(true); // 缩放至屏幕的大小 settings.setLoadWithOverviewMode(true); // 设置内置的缩放控件(若SupportZoom为false,该设置项无效) settings.setBuiltInZoomControls(true); // 设置缓存模式 // LOAD_DEFAULT 根据HTTP协议header中设置的cache-control属性来执行加载策略 // LOAD_CACHE_ELSE_NETWORK 只要本地有无论是否过期都从本地获取 settings.setCacheMode(WebSettings.LOAD_DEFAULT); settings.setDomStorageEnabled(true); // 设置AppCache 需要H5页面配置manifest文件(官方已不推介使用) String appCachePath = getContext().getCacheDir().getAbsolutePath(); settings.setAppCachePath(appCachePath); settings.setAppCacheEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // 强制开启android webview debug模式使用Chrome inspect(https://developers.google.com/web/tools/chrome-devtools/remote-debugging/) WebView.setWebContentsDebuggingEnabled(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().setAcceptThirdPartyCookies(this, true); } }
Example 9
Source File: WebViewFragment.java From quill with MIT License | 5 votes |
@SuppressLint("SetJavaScriptEnabled") @NonNull @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @LayoutRes int layoutId = getArguments().getInt(KEY_LAYOUT_ID); View view = inflater.inflate(layoutId, container, false); // not using ButterKnife to ensure WebView is private // but still need to call bindView() to maintain base class contract bindView(view); mWebView = (WebView) view.findViewById(R.id.web_view); mUrl = getArguments().getString(BundleKeys.URL); if (TextUtils.isEmpty(mUrl)) { throw new IllegalArgumentException("Empty URL passed to WebViewFragment!"); } Crashlytics.log(Log.DEBUG, TAG, "Loading URL: " + mUrl); WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); // enable remote debugging if (0 != (getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } mWebView.setWebViewClient(new DefaultWebViewClient()); mWebView.loadUrl(mUrl); return view; }
Example 10
Source File: BridgeWebView.java From JsWebView with Apache License 2.0 | 5 votes |
private void init() { this.setVerticalScrollBarEnabled(false); this.setHorizontalScrollBarEnabled(false); this.getSettings().setJavaScriptEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } this.setWebViewClient(generateBridgeWebViewClient()); }
Example 11
Source File: SystemWebViewEngine.java From ultimate-cordova-webview-app with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private void enableRemoteDebugging() { try { WebView.setWebContentsDebuggingEnabled(true); } catch (IllegalArgumentException e) { LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! "); e.printStackTrace(); } }
Example 12
Source File: SystemWebViewEngine.java From app-icon with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private void enableRemoteDebugging() { try { WebView.setWebContentsDebuggingEnabled(true); } catch (IllegalArgumentException e) { LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! "); e.printStackTrace(); } }
Example 13
Source File: SystemWebViewEngine.java From lona with GNU General Public License v3.0 | 5 votes |
private void enableRemoteDebugging() { try { WebView.setWebContentsDebuggingEnabled(true); } catch (IllegalArgumentException e) { LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! "); e.printStackTrace(); } }
Example 14
Source File: BitWebViewFragment.java From tysq-android with GNU General Public License v3.0 | 5 votes |
@Override protected void initView(View view) { initWebView(mWebView); initWebViewSetting(mWebView.getSettings()); mWebView.loadUrl(this.mUrl, BitWebViewManager.getInstance().getWebViewConfig().getHeader()); WebView.setWebContentsDebuggingEnabled(true); }
Example 15
Source File: JSWebView.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @SuppressLint({"SetJavaScriptEnabled", "NewApi", "ObsoleteSdkInt"}) public void initializeSettings(WebSettings settings) { settings.setJavaScriptEnabled(true); addJavascriptInterface(new JavaScriptUtil(), "DappJsBridge"); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { settings.setAppCacheMaxSize(Long.MAX_VALUE); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { settings.setEnableSmoothTransition(true); } if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) { settings.setMediaPlaybackRequiresUserGesture(true); } WebView.setWebContentsDebuggingEnabled(true); settings.setDomStorageEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setAppCacheEnabled(true); settings.setCacheMode(WebSettings.LOAD_DEFAULT); settings.setLoadsImagesAutomatically(true); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); settings.setDatabaseEnabled(true); settings.setDisplayZoomControls(false); settings.setAllowContentAccess(true); settings.setAllowFileAccess(false); settings.setRenderPriority(WebSettings.RenderPriority.LOW); setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); settings.setDefaultTextEncodingName("utf-8"); settings.setAllowFileAccessFromFileURLs(false); settings.setAllowUniversalAccessFromFileURLs(false); // 特别注意:5.1以上默认禁止了https和http混用,以下方式是开启 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW); } }
Example 16
Source File: SystemWebViewEngine.java From BigDataPlatform with GNU General Public License v3.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private void enableRemoteDebugging() { try { WebView.setWebContentsDebuggingEnabled(true); } catch (IllegalArgumentException e) { LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! "); e.printStackTrace(); } }
Example 17
Source File: ReactWebViewManager.java From react-native-GPay with MIT License | 4 votes |
@Override @TargetApi(Build.VERSION_CODES.LOLLIPOP) protected WebView createViewInstance(ThemedReactContext reactContext) { ReactWebView webView = createReactWebViewInstance(reactContext); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage message) { if (ReactBuildConfig.DEBUG) { return super.onConsoleMessage(message); } // Ignore console logs in non debug builds. return true; } @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); } }); reactContext.addLifecycleEventListener(webView); mWebViewConfig.configWebView(webView); WebSettings settings = webView.getSettings(); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setDomStorageEnabled(true); settings.setAllowFileAccess(false); settings.setAllowContentAccess(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { settings.setAllowFileAccessFromFileURLs(false); setAllowUniversalAccessFromFileURLs(webView, false); } setMixedContentMode(webView, "never"); // Fixes broken full-screen modals/galleries due to body height being 0. webView.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); setGeolocationEnabled(webView, false); if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } return webView; }
Example 18
Source File: BaseWebActivity.java From Hentoid with Apache License 2.0 | 4 votes |
@SuppressLint("SetJavaScriptEnabled") private void initWebView() { try { webView = new NestedScrollWebView(this); } catch (Resources.NotFoundException e) { // Some older devices can crash when instantiating a WebView, due to a Resources$NotFoundException // Creating with the application Context fixes this, but is not generally recommended for view creation webView = new NestedScrollWebView(Helper.getFixedContext(this)); } webView.setHapticFeedbackEnabled(false); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if (newProgress == 100) { swipeLayout.post(() -> swipeLayout.setRefreshing(false)); } else { swipeLayout.post(() -> swipeLayout.setRefreshing(true)); } } }); boolean bWebViewOverview = Preferences.getWebViewOverview(); int webViewInitialZoom = Preferences.getWebViewInitialZoom(); if (bWebViewOverview) { webView.getSettings().setLoadWithOverviewMode(false); webView.setInitialScale(webViewInitialZoom); Timber.d("WebView Initial Scale: %s%%", webViewInitialZoom); } else { webView.setInitialScale(Preferences.Default.PREF_WEBVIEW_INITIAL_ZOOM_DEFAULT); webView.getSettings().setLoadWithOverviewMode(true); } if (BuildConfig.DEBUG) WebView.setWebContentsDebuggingEnabled(true); webClient = getWebClient(); webView.setWebViewClient(webClient); // Download immediately on long click on a link / image link if (Preferences.isBrowserQuickDl()) webView.setOnLongClickListener(v -> { WebView.HitTestResult result = webView.getHitTestResult(); String url = ""; // Plain link if (result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE && result.getExtra() != null) url = result.getExtra(); // Image link (https://stackoverflow.com/a/55299801/8374722) if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { Handler handler = new Handler(); Message message = handler.obtainMessage(); webView.requestFocusNodeHref(message); url = message.getData().getString("url"); } if (url != null && !url.isEmpty() && webClient.isBookGallery(url)) { // Launch on a new thread to avoid crashes webClient.parseResponseAsync(url); return true; } else { return false; } }); Timber.i("Using agent %s", webView.getSettings().getUserAgentString()); chromeVersion = getChromeVersion(this); WebSettings webSettings = webView.getSettings(); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setUserAgentString(Consts.USER_AGENT_NEUTRAL); webSettings.setDomStorageEnabled(true); webSettings.setUseWideViewPort(true); webSettings.setJavaScriptEnabled(true); webSettings.setLoadWithOverviewMode(true); CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); SwipeRefreshLayout refreshLayout = findViewById(R.id.swipe_container); if (refreshLayout != null) refreshLayout.addView(webView, layoutParams); }
Example 19
Source File: WebViewManager.java From GotoBrowser with GNU General Public License v3.0 | 4 votes |
public static void setWebViewDebugging(boolean enabled) { WebView.setWebContentsDebuggingEnabled(enabled); }
Example 20
Source File: BrowserApp.java From JumpGo with Mozilla Public License 2.0 | 4 votes |
@Override public void onCreate() { super.onCreate(); if (BuildConfig.DEBUG) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .build()); } final Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, @NonNull Throwable ex) { if (BuildConfig.DEBUG) { FileUtils.writeCrashToStorage(ex); } if (defaultHandler != null) { defaultHandler.uncaughtException(thread, ex); } else { System.exit(2); } } }); sAppComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build(); sAppComponent.inject(this); Schedulers.worker().execute(new Runnable() { @Override public void run() { List<HistoryItem> oldBookmarks = LegacyBookmarkManager.destructiveGetBookmarks(BrowserApp.this); if (!oldBookmarks.isEmpty()) { // If there are old bookmarks, import them mBookmarkModel.addBookmarkList(oldBookmarks).subscribeOn(Schedulers.io()).subscribe(); } else if (mBookmarkModel.count() == 0) { // If the database is empty, fill it from the assets list List<HistoryItem> assetsBookmarks = BookmarkExporter.importBookmarksFromAssets(BrowserApp.this); mBookmarkModel.addBookmarkList(assetsBookmarks).subscribeOn(Schedulers.io()).subscribe(); } } }); if (mPreferenceManager.getUseLeakCanary() && !isRelease()) { LeakCanary.install(this); } if (!isRelease() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } registerActivityLifecycleCallbacks(new MemoryLeakUtils.LifecycleAdapter() { @Override public void onActivityDestroyed(Activity activity) { Log.d(TAG, "Cleaning up after the Android framework"); MemoryLeakUtils.clearNextServedView(activity, BrowserApp.this); } }); }