def acceptNavigationRequest(self, url, _type, is_main_frame) -> bool: """ * Decide if we navigate to a URL * :param url: QtCore.QUrl * :param _type: QWebEnginePage.NavigationType * :param is_main_frame:bool """ self.url = url.toString() self.page = JWebPage(self.profile(), self.view(), self.config) # Redirect new tabs to same window self.page.urlChanged.connect(self._on_url_changed) if self.config['webview']["online"]: if _type == QWebEnginePage.WebWindowType.WebBrowserTab: if self.config['webview']["urlRules"]: # Check for URL rules on new tabs if self.url.startswith(self.config['webview']["urlRules"] ["WebBrowserTab"]): self.open_window(self.url) return False elif check_url_rules("WebBrowserTab", self.url, self.config['webview']["urlRules"]): print(f"Redirecting WebBrowserTab^ to same window") return True else: print(f"Deny WebBrowserTab:{self.url}") # check against WebBrowserWindow list to avoid duplicate dialogs if not check_url_rules( "WebBrowserWindow", self.url, self.config['webview']["urlRules"]): self._dialog_open_in_browser() return False else: return True elif _type == QWebEnginePage.WebBrowserBackgroundTab: print(f"WebBrowserBackgroundTab request:{self.url}") return True elif _type == QWebEnginePage.WebBrowserWindow: if self.config['webview']["urlRules"] and self.config[ 'webview']["online"]: # Check URL rules on new windows if check_url_rules("WebBrowserWindow", self.url, self.config['webview']["urlRules"]): print(f"Deny WebBrowserWindow:{self.url}") self._dialog_open_in_browser() return False else: print(f"Allow WebBrowserWindow:{self.url}") return True else: return True elif _type == QWebEnginePage.WebDialog: return True return True
def interceptRequest(self, info) -> None: """ * All method calls to the profile on the main thread will block until execution of this function is finished. * :param info: QWebEngineUrlRequestInfo """ if self.config["url_rules"] is not None: # If we have any URL's in the block dictionary url = info.requestUrl().toString() try: if check_url_rules("Block", url, self.config["url_rules"]["block"]): # block url's info.block(True) print(f"Blocked:{url}") except KeyError: pass if self.config["debug"]: url = info.requestUrl().toString() resource = info.resourceType() if resource == QWebEngineUrlRequestInfo.ResourceType.ResourceTypeMainFrame: print(f"Intercepted link:{url}") elif resource != QWebEngineUrlRequestInfo.ResourceType.ResourceTypeMainFrame: print(f"Intercepted resource:{url}")
def acceptNavigationRequest(self, url, _type, is_main_frame) -> bool: """ * Decide if we navigate to a URL * :param url: PySide2.QtCore.QUrl * :param _type: QWebEnginePage.NavigationType * :param is_main_frame:bool """ self.url = url.toString() self.page = JWebPage(self.icon, self.debug, self.online, self.url_rules) # Redirect new tabs to same window self.page.urlChanged.connect(self._on_url_changed) if not self.online and self.url.startswith("ipc:"): # * Link's that starts with [ ipc:somefunction() ] trigger's the two way communication system bettwen HTML # and Python # * This only works if online is set to false if self.debug: print(f"IPC call: {self.url}") try: from IPC import _Communication except ImportError: from JAK.IPC import _Communication _Communication().activate(self, self.url) return False elif _type == QWebEnginePage.WebWindowType.WebBrowserTab: if self.url_rules and self.online: # Check for URL rules on new tabs if self.url.startswith(self.url_rules["WebBrowserTab"]): self.open_window(self.url) return False elif check_url_rules("WebBrowserTab", self.url, self.url_rules): print(f"Redirecting WebBrowserTab^ to same window") return True else: print(f"Deny WebBrowserTab:{self.url}") # check against WebBrowserWindow list to avoid duplicate dialogs if not check_url_rules("WebBrowserWindow", self.url, self.url_rules): self._dialog_open_in_browser() return False else: return True elif _type == QWebEnginePage.WebBrowserBackgroundTab: print(f"WebBrowserBackgroundTab request:{self.url}") return True elif _type == QWebEnginePage.WebBrowserWindow: if self.url_rules and self.online: # Check URL rules on new windows if check_url_rules("WebBrowserWindow", self.url, self.url_rules): print(f"Deny WebBrowserWindow:{self.url}") self._dialog_open_in_browser() return False else: print(f"Allow WebBrowserWindow:{self.url}") return True else: return True elif _type == QWebEnginePage.WebDialog: return True return True