Exemple #1
0
    def call_userscript(self, elem, context):
        """Call a userscript from a hint.

        Args:
            elem: The QWebElement to use in the userscript.
            context: The HintContext to use.
        """
        cmd = context.args[0]
        args = context.args[1:]
        env = {
            'QUTE_MODE': 'hints',
            'QUTE_SELECTED_TEXT': str(elem),
            'QUTE_SELECTED_HTML': elem.outer_xml(),
        }
        url = elem.resolve_url(context.baseurl)
        if url is not None:
            env['QUTE_URL'] = url.toString(QUrl.FullyEncoded)

        try:
            userscripts.run_async(context.tab,
                                  cmd,
                                  *args,
                                  win_id=self._win_id,
                                  env=env)
        except userscripts.UnsupportedError as e:
            raise HintingError(str(e))
Exemple #2
0
    def call_userscript(self, elem: webelem.AbstractWebElement,
                        context: HintContext) -> None:
        """Call a userscript from a hint.

        Args:
            elem: The QWebElement to use in the userscript.
            context: The HintContext to use.
        """
        # lazy import to avoid circular import issues
        from qutebrowser.commands import userscripts

        cmd = context.args[0]
        args = context.args[1:]
        flags = QUrl.FullyEncoded

        env = {
            'QUTE_MODE': 'hints',
            'QUTE_SELECTED_TEXT': str(elem),
            'QUTE_SELECTED_HTML': elem.outer_xml(),
            'QUTE_CURRENT_URL':
            context.baseurl.toString(flags),  # type: ignore[arg-type]
        }

        url = elem.resolve_url(context.baseurl)
        if url is not None:
            env['QUTE_URL'] = url.toString(flags)  # type: ignore[arg-type]

        try:
            userscripts.run_async(context.tab,
                                  cmd,
                                  *args,
                                  win_id=self._win_id,
                                  env=env)
        except userscripts.Error as e:
            raise HintingError(str(e))
Exemple #3
0
    def call_userscript(self, elem, context):
        """Call a userscript from a hint.

        Args:
            elem: The QWebElement to use in the userscript.
            context: The HintContext to use.
        """
        cmd = context.args[0]
        args = context.args[1:]
        env = {"QUTE_MODE": "hints", "QUTE_SELECTED_TEXT": str(elem), "QUTE_SELECTED_HTML": elem.outer_xml()}
        url = elem.resolve_url(context.baseurl)
        if url is not None:
            env["QUTE_URL"] = url.toString(QUrl.FullyEncoded)

        try:
            userscripts.run_async(context.tab, cmd, *args, win_id=self._win_id, env=env)
        except userscripts.UnsupportedError as e:
            raise HintingError(str(e))
    def call_userscript(self, elem, context):
        """Call a userscript from a hint.

        Args:
            elem: The QWebElement to use in the userscript.
            context: The HintContext to use.
        """
        cmd = context.args[0]
        args = context.args[1:]
        env = {
            'QUTE_MODE': 'hints',
            'QUTE_SELECTED_TEXT': str(elem),
            'QUTE_SELECTED_HTML': elem.outer_xml(),
        }
        url = elem.resolve_url(context.baseurl)
        if url is not None:
            env['QUTE_URL'] = url.toString(QUrl.FullyEncoded)

        try:
            userscripts.run_async(context.tab, cmd, *args, win_id=self._win_id,
                                  env=env)
        except userscripts.UnsupportedError as e:
            message.error(self._win_id, str(e), immediately=True)
Exemple #5
0
def test_unsupported(monkeypatch, tabbed_browser_stubs):
    monkeypatch.setattr(userscripts.os, 'name', 'toaster')
    with pytest.raises(userscripts.UnsupportedError) as excinfo:
        userscripts.run_async(tab=None, cmd=None, win_id=0, env=None)
    expected = "Userscripts are not supported on this platform!"
    assert str(excinfo.value) == expected
def test_unsupported(tabbed_browser_stubs):
    with pytest.raises(userscripts.UnsupportedError, match="Userscripts are "
                       "not supported on this platform!"):
        userscripts.run_async(tab=None, cmd=None, win_id=0, env=None)
def test_unsupported(monkeypatch, tabbed_browser_stubs):
    monkeypatch.setattr(userscripts.os, 'name', 'toaster')
    with pytest.raises(userscripts.UnsupportedError) as excinfo:
        userscripts.run_async(tab=None, cmd=None, win_id=0, env=None)
    expected = "Userscripts are not supported on this platform!"
    assert str(excinfo.value) == expected
Exemple #8
0
def test_unsupported(monkeypatch, tabbed_browser_stubs):
    monkeypatch.setattr(userscripts.os, 'name', 'toaster')
    with pytest.raises(userscripts.UnsupportedError,
                       match="Userscripts are "
                       "not supported on this platform!"):
        userscripts.run_async(tab=None, cmd=None, win_id=0, env=None)
def test_unsupported(monkeypatch, tabbed_browser_stubs):
    monkeypatch.setattr(userscripts.os, 'name', 'toaster')
    with pytest.raises(userscripts.UnsupportedError, match="Userscripts are "
                       "not supported on this platform!"):
        userscripts.run_async(tab=None, cmd=None, win_id=0, env=None)
def test_unsupported(tabbed_browser_stubs):
    with pytest.raises(userscripts.UnsupportedError, match="Userscripts are "
                       "not supported on this platform!"):
        userscripts.run_async(tab=None, cmd=None, win_id=0, env=None)