javascript - How to get cursor position in a Chrome DevTools source editor from extension? - Stack Overflow

I develop Open in Editor extension for Google Chrome DevTools that allows to open source file in extern

I develop Open in Editor extension for Google Chrome DevTools that allows to open source file in external editor using context menu.

It works perfectly in most of cases (Network panel, Performance panel, Style inspector, and so on) when file location in UI contains a line number (like jquery.js:2191).
The only exception is Sources panel. A chrome.devtools.panels.setOpenResourceHandler callback function doesn't receive a line number.

Does DevTools has some API to get a position of cursor in source editor from setOpenResourceHandler() callback?

I develop Open in Editor extension for Google Chrome DevTools that allows to open source file in external editor using context menu.

It works perfectly in most of cases (Network panel, Performance panel, Style inspector, and so on) when file location in UI contains a line number (like jquery.js:2191).
The only exception is Sources panel. A chrome.devtools.panels.setOpenResourceHandler callback function doesn't receive a line number.

Does DevTools has some API to get a position of cursor in source editor from setOpenResourceHandler() callback?

Share Improve this question edited Jul 20, 2017 at 8:44 myfunkyside 3,9501 gold badge20 silver badges32 bronze badges asked Jul 17, 2017 at 11:18 Evgeniy GeneralovEvgeniy Generalov 1,37116 silver badges26 bronze badges 3
  • 6 Maybe you could check this developers.google./web/tools/chrome-devtools/inspect-styles and this developers.google./web/updates/2015/05/… but there is still no method mention like it. Maybe this is not supported yet as of now. – Mr.Rebot Commented Jul 21, 2017 at 9:58
  • @Mr.Rebot, thank you for an advice. I've raised the issue bugs.chromium/p/chromium/issues/detail?id=747888 . – Evgeniy Generalov Commented Jul 24, 2017 at 11:09
  • Please edit the question to be on-topic: include a minimal reproducible example that duplicates the problem. For Chrome extensions or Firefox WebExtensions you almost always need to include your manifest.json and some of the background, content, and/or popup scripts/HTML, and often webpage HTML/scripts. Questions seeking debugging help ("why isn't my code working the way I want?") must include: (1) the desired behavior, (2) a specific problem or error and (3) the shortest code necessary to reproduce it in the question itself. Please also see: What topics can I ask about here?, and How to Ask. – Makyen Commented Oct 6, 2017 at 21:24
Add a ment  | 

1 Answer 1

Reset to default 2

This has been explained as per reported Chrome Issue 747888:

So first of all, setOpenResourceHandle() is for the cases when users click a link (e.g. a linkified location in console) that normally results in opening a source tab in DevTools, it's not meant to be fired when a file is explicitly opened in the source panel. For changes of the file/position within the sources tab, we've got chrome.devtools.panels.sources.onSelectionChanged (see a layout test for example usage) that was recently brought back by @jacobr).

Here is the mentioned code example:

function extension_testElementsOnSelectionChanged(nextTest)
{
    function onSelectionChanged()
    {
        webInspector.panels.elements.onSelectionChanged.removeListener(onSelectionChanged);
        output("onSelectionChanged fired");
        nextTest();
    }
    webInspector.panels.elements.onSelectionChanged.addListener(onSelectionChanged);
    webInspector.inspectedWindow.eval("inspect(document.body.children[0]), 0");
}

function extension_testSourcesOnSelectionChangedShowFile(nextTest)
{
    function onSelectionChanged(selectionInfo)
    {
        webInspector.panels.sources.onSelectionChanged.removeListener(onSelectionChanged);
        output("sources onSelectionChanged fired, selectionInfo:");
        dumpObject(selectionInfo, {url: "url"});
        nextTest();
    }
    webInspector.panels.sources.onSelectionChanged.addListener(onSelectionChanged);
    evaluateOnFrontend("InspectorTest.showScriptSource(\"test-script.js\")");
}

function extension_testSourcesOnSelectionChangedShowFileAndLine(nextTest)
{
    webInspector.inspectedWindow.eval("location.href", function(inspectedPageURL) {
        function onSelectionChanged(selectionInfo)
        {
            webInspector.panels.sources.onSelectionChanged.removeListener(onSelectionChanged);
            output("sources onSelectionChanged fired, selectionInfo:");
            dumpObject(selectionInfo, {url: "url"});
            nextTest();
        }
        webInspector.panels.sources.onSelectionChanged.addListener(onSelectionChanged);

        var basePath = inspectedPageURL.replace(/\/[^/]*$/, "/");
        webInspector.panels.openResource(basePath + "resources/test-script.js", 2);
    });
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745285464a4620531.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信