简体   繁体   English

捕获并发送特定的可见标签

[英]Capture and send specific visible tab

in my background.js i will capture a specific area in a div. 在我的background.js我将捕获div中的特定区域。

My code looks like 我的代码看起来像

function main()
{
    chrome.tabs.query( {'active': true}, check_tab );
}
function check_tab( tabs )
{
    for (i = 0; i < tabs.length; i++) { 
        var url = tabs[i].url;
        if ( -1 < url.indexOf( "https://www.specificurl" ) ) {
            chrome.tabs.captureVisibleTab( null, {'format': "png"}, function(img){
                $.ajax({
                    type: "POST",
                    url: "http://mywebsite.com/doSomething.php",
                    data: "img=" + img
                });
            });
        }
    }
}

I would like crop the image and send or send image with position, width and height to cut . 我想crop the image and sendsend image with position, width and height to cut Whether it's the first case or the second case, I need access to the position, the width and height of the div to cut correctly. 无论是第一种情况还是第二种情况,我都需要访问div的位置,宽度和高度才能正确剪切。 How can I get the source code of the webpage by chrome.tabs ? 如何通过chrome.tabs获取网页的源代码?

Thanks 谢谢

To get the html of current page, use var html = $('html').html(); 要获取当前页面的html,请使用var html = $('html').html(); or document.documentElement.innerHTML document.documentElement.innerHTML

chrome.tabs.executeScript(tabs[0].id, {"code": "var html = document.documentElement.innerHTML;"}, function(html) {
    console.log(html); 
});

Take a look at this open source project , it allows you to capture selected area in a web page, the basic idea would be using canvas to draw the image, then you can crop the canvas with specific position, width and height. 看一下这个开源项目 ,它允许您捕获网页中的选定区域,其基本思想是使用画布绘制图像,然后可以按特定的位置,宽度和高度裁剪画布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM