Get :debug-dump-page to work
This commit is contained in:
parent
0c1e266073
commit
3ee58fdea3
@ -1294,22 +1294,20 @@ class CommandDispatcher:
|
||||
dest: Where to write the file to.
|
||||
plain: Write plain text instead of HTML.
|
||||
"""
|
||||
web_view = self._current_widget()
|
||||
mainframe = web_view.page().mainFrame()
|
||||
if plain:
|
||||
data = mainframe.toPlainText()
|
||||
else:
|
||||
data = mainframe.toHtml()
|
||||
|
||||
tab = self._current_widget()
|
||||
dest = os.path.expanduser(dest)
|
||||
|
||||
try:
|
||||
with open(dest, 'w', encoding='utf-8') as f:
|
||||
f.write(data)
|
||||
except OSError as e:
|
||||
raise cmdexc.CommandError('Could not write page: {}'.format(e))
|
||||
else:
|
||||
message.info(self._win_id, "Dumped page to {}.".format(dest))
|
||||
def callback(data):
|
||||
try:
|
||||
with open(dest, 'w', encoding='utf-8') as f:
|
||||
f.write(data)
|
||||
except OSError as e:
|
||||
message.error(self._win_id, 'Could not write page: {}'.format(e))
|
||||
else:
|
||||
message.info(self._win_id, "Dumped page to {}.".format(dest))
|
||||
|
||||
tab.dump_async(callback, plain=plain)
|
||||
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', name='help',
|
||||
scope='window')
|
||||
|
@ -150,6 +150,14 @@ class AbstractTab(QWidget):
|
||||
def openurl(self, url):
|
||||
raise NotImplementedError
|
||||
|
||||
def dump_async(self, callback=None, *, plain=False):
|
||||
"""Dump the current page to a file ascync.
|
||||
|
||||
The given callback will be called with the result when dumping is
|
||||
complete.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def __repr__(self):
|
||||
url = utils.elide(self.cur_url.toDisplayString(QUrl.EncodeUnicode),
|
||||
100)
|
||||
|
@ -83,6 +83,12 @@ class WebEngineViewTab(tab.AbstractTab):
|
||||
def scroll_pos(self):
|
||||
return (0, 0)
|
||||
|
||||
def dump_async(self, callback=None, *, plain=False):
|
||||
if plain:
|
||||
self._widget.page().toPlainText(callback)
|
||||
else:
|
||||
self._widget.page().toHtml(callback)
|
||||
|
||||
def _connect_signals(self):
|
||||
view = self._widget
|
||||
page = view.page()
|
||||
|
@ -89,6 +89,13 @@ class WebViewTab(tab.AbstractTab):
|
||||
def scroll_pos(self):
|
||||
return self._widget.scroll_pos
|
||||
|
||||
def dump_async(self, callback=None, *, plain=False):
|
||||
frame = self._widget.page().mainFrame()
|
||||
if plain:
|
||||
callback(frame.toPlainText())
|
||||
else:
|
||||
callback(frame.toHtml())
|
||||
|
||||
def _connect_signals(self):
|
||||
view = self._widget
|
||||
page = view.page()
|
||||
|
Loading…
Reference in New Issue
Block a user