Enabling Extensions on PyQt
-
wrote on 24 Oct 2021, 19:19 last edited by
Hi, I've been trying to make a browser in PyQt and I would like to be able to get extensions for it.
Any tips are helpful!
Thanks in advance!
Here is the code:import sys from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtWebEngineWidgets import * class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.browser = QWebEngineView() self.browser.setUrl(QUrl('http://google.com')) self.tab_wgt = QTabWidget() self.tab_wgt.addTab(self.browser, "home") self.tab_wgt.setTabsClosable(True) self.tab_wgt.tabCloseRequested.connect(lambda i: self.tab_wgt.removeTab(i)) self.tab_wgt.currentChanged.connect(self.tab_changed) self.setCentralWidget(self.tab_wgt) self.showMaximized() # nav bar navbar = QToolBar() self.addToolBar(navbar) back_btn = QAction('Back', self) back_btn.triggered.connect(self.browser.back) navbar.addAction(back_btn) forward_btn = QAction('Forward', self) forward_btn.triggered.connect(self.browser.forward) navbar.addAction(forward_btn) reload_btn = QAction('Reload', self) reload_btn.triggered.connect(self.browser.reload) navbar.addAction(reload_btn) home_btn = QAction('Home', self) home_btn.triggered.connect(self.navigate_home) navbar.addAction(home_btn) new_btn = QAction('New Tab', self) new_btn.triggered.connect(self.newtab) navbar.addAction(new_btn) self.url_bar = QLineEdit() self.url_bar.returnPressed.connect(self.navigate_to_url) navbar.addWidget(self.url_bar) self.browser.urlChanged.connect(self.update_url) def navigate_home(self): self.browser.setUrl(QUrl('http://google.com')) def newtab(self): browser = QWebEngineView() self.tab_wgt.addTab(browser, "about:blank") self.tab_wgt.setCurrentWidget(browser) self.url_bar.setText("about:blank") browser.titleChanged.connect(self.update_title) browser.urlChanged.connect(self.update_url) def tab_changed(self, i): browser: QWebEngineView = self.tab_wgt.widget(i) if browser: text = browser.url().toString() if text: self.url_bar.setText(text) else: self.url_bar.setText("about:blank") def navigate_to_url(self): if "https://www." in self.url_bar.text(): url = self.url_bar.text() else: url = "https://www." + self.url_bar.text() browser: QWebEngineView = self.tab_wgt.currentWidget() browser.setUrl(QUrl(url)) def update_url(self, url): self.url_bar.setText(url.toString()) def update_title(self, title): self.tab_wgt.setTabText(self.tab_wgt.currentIndex(), title) class WebPage(QWebEnginePage): adblocker = Filter(open('easylist.txt', encoding="utf8")) def __init__(self, parent=None): super().__init__(parent) def acceptNavigationRequest(self, url, _type, isMainFrame): urlString = url.toString() resp = False resp = WebPage.adblocker.match(url.toString()) if resp: print("Blocking url --- "+url.toString()) return False else: print("TYPE", _type) return True return QWebEnginePage.acceptNavigationRequest(self, url, _type, isMainFrame) app = QApplication(sys.argv) QApplication.setApplicationName("Jeswwws") window = MainWindow() app.exec_()
-
Hi, I've been trying to make a browser in PyQt and I would like to be able to get extensions for it.
Any tips are helpful!
Thanks in advance!
Here is the code:import sys from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtWebEngineWidgets import * class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.browser = QWebEngineView() self.browser.setUrl(QUrl('http://google.com')) self.tab_wgt = QTabWidget() self.tab_wgt.addTab(self.browser, "home") self.tab_wgt.setTabsClosable(True) self.tab_wgt.tabCloseRequested.connect(lambda i: self.tab_wgt.removeTab(i)) self.tab_wgt.currentChanged.connect(self.tab_changed) self.setCentralWidget(self.tab_wgt) self.showMaximized() # nav bar navbar = QToolBar() self.addToolBar(navbar) back_btn = QAction('Back', self) back_btn.triggered.connect(self.browser.back) navbar.addAction(back_btn) forward_btn = QAction('Forward', self) forward_btn.triggered.connect(self.browser.forward) navbar.addAction(forward_btn) reload_btn = QAction('Reload', self) reload_btn.triggered.connect(self.browser.reload) navbar.addAction(reload_btn) home_btn = QAction('Home', self) home_btn.triggered.connect(self.navigate_home) navbar.addAction(home_btn) new_btn = QAction('New Tab', self) new_btn.triggered.connect(self.newtab) navbar.addAction(new_btn) self.url_bar = QLineEdit() self.url_bar.returnPressed.connect(self.navigate_to_url) navbar.addWidget(self.url_bar) self.browser.urlChanged.connect(self.update_url) def navigate_home(self): self.browser.setUrl(QUrl('http://google.com')) def newtab(self): browser = QWebEngineView() self.tab_wgt.addTab(browser, "about:blank") self.tab_wgt.setCurrentWidget(browser) self.url_bar.setText("about:blank") browser.titleChanged.connect(self.update_title) browser.urlChanged.connect(self.update_url) def tab_changed(self, i): browser: QWebEngineView = self.tab_wgt.widget(i) if browser: text = browser.url().toString() if text: self.url_bar.setText(text) else: self.url_bar.setText("about:blank") def navigate_to_url(self): if "https://www." in self.url_bar.text(): url = self.url_bar.text() else: url = "https://www." + self.url_bar.text() browser: QWebEngineView = self.tab_wgt.currentWidget() browser.setUrl(QUrl(url)) def update_url(self, url): self.url_bar.setText(url.toString()) def update_title(self, title): self.tab_wgt.setTabText(self.tab_wgt.currentIndex(), title) class WebPage(QWebEnginePage): adblocker = Filter(open('easylist.txt', encoding="utf8")) def __init__(self, parent=None): super().__init__(parent) def acceptNavigationRequest(self, url, _type, isMainFrame): urlString = url.toString() resp = False resp = WebPage.adblocker.match(url.toString()) if resp: print("Blocking url --- "+url.toString()) return False else: print("TYPE", _type) return True return QWebEnginePage.acceptNavigationRequest(self, url, _type, isMainFrame) app = QApplication(sys.argv) QApplication.setApplicationName("Jeswwws") window = MainWindow() app.exec_()
wrote on 24 Oct 2021, 19:23 last edited by@Slim-Shady If you mean chrome extensions then it is not possible because that does not implement chromium.
-
@Slim-Shady If you mean chrome extensions then it is not possible because that does not implement chromium.
wrote on 24 Oct 2021, 19:30 last edited by@eyllanesc Not only Chrome extensions, any browser as long as it at least has any kind of ad blocker
-
@eyllanesc Not only Chrome extensions, any browser as long as it at least has any kind of ad blocker
wrote on 24 Oct 2021, 19:33 last edited by@Slim-Shady One thing is the adblock and another the extensions. An adblock can be implemented through extensions. On the other hand, extensions are popular so each browser implements it but it is not a technology that chromium implements. If you want to implement an ad blocker then check https://stackoverflow.com/questions/53330056/pyqt5-pyside2-adblock/53330741#53330741
-
@Slim-Shady One thing is the adblock and another the extensions. An adblock can be implemented through extensions. On the other hand, extensions are popular so each browser implements it but it is not a technology that chromium implements. If you want to implement an ad blocker then check https://stackoverflow.com/questions/53330056/pyqt5-pyside2-adblock/53330741#53330741
wrote on 24 Oct 2021, 19:45 last edited by@eyllanesc Thanks for that. I've checked it out but I don't know how to implement it with my code. Could you give me a hand, please?
-
@eyllanesc Thanks for that. I've checked it out but I don't know how to implement it with my code. Could you give me a hand, please?
wrote on 24 Oct 2021, 19:50 last edited by@Slim-Shady In my answer there is a complete example, I do not know what more help you are waiting for, bye. Try something and when something fails then just ask for help. Bye.
-
wrote on 25 Oct 2021, 12:57 last edited by
Yes, I've seen the example, I just don't know how to make it run with my code. That's the "more help" that I need.
-
Yes, I've seen the example, I just don't know how to make it run with my code. That's the "more help" that I need.
wrote on 25 Oct 2021, 13:06 last edited by@Slim-Shady I expect some effort on the part of the OP, if there is not then he does not ask for help but wants them to do their work so he must pay for it. So it's one thing to help and another to want them to work for you for free.
-
wrote on 25 Oct 2021, 13:51 last edited by
I'm sorry if that's how you see it, but I don't want you to do the work for me, I just need a little help.
1/9