Save source of popup window as string?

后端 未结 2 1355
傲寒
傲寒 2020-12-11 13:41

Is there a way to save the source of a popup window outside of my domain as a string, opened by:

window.open(\'html\');

Also another way of

相关标签:
2条回答
  • 2020-12-11 14:06

    If you're really wanting to build a small app to accomplish what you're describing, remember you can right-click and view nearly any page source in Chrome, including tabs, home page, and some other places. Ironically or not, the View Source page is the only one I've found that I couldn't seem to get at the source, although I seem to found out what it's URI is:

    chrome-devtools://devtools/devtools.html
    

    But nothing comes up, except if I search for that URI. Here are some URIs to open and try Right-Click + View Source to see what you get:

    * Regular tab (new)
    * view-source:chrome://newtab/
    * view-source:chrome://extensions-frame        // This has file handlers for extensions
    * view-source:chrome://settings-frame/settings // Go to lines `2907`
    * view-source:chrome://memory-redirect/
    * view-source:chrome://downloads/
    * view-source:chrome://settings-frame/options_bundle.js // This one has all kinds of good stuff
    * view-source:chrome://resources/js/util.js 
    * view-source:chrome://chrome/uber.js
    * view-source:chrome://sync-internals/
    * view-source:chrome://resources/js/cr/ui/array_data_model.js
    * view-source:chrome://resources/js/cr/ui/list_item.js
    * view-source:chrome://resources/js/cr/ui/tabs.js
    

    The following two practice programs and more you can find from:

    http://developer.chrome.com/extensions/tabs.html#samples

    Live HTTP Headers, headers.js - What the below shows is how you may be able to attach a listener to the `window.onlaod`` event and when the response is received, be notified so you can grab the source (not the browser's parsed and computed source).

    window.addEventListener("load", function() {
        chrome.debugger.sendCommand({tabId:tabId}, "Network.enable");
        chrome.debugger.onEvent.addListener(onEvent);
    });
    
    } else if (message == "Network.responseReceived") {
        appendResponse(params.requestId, params.response);
    }
    

    Download Selected Links - The second a from a file called popup.js.

    // Send back to the popup a sorted deduped list of valid link URLs on this page.
    // The popup injects this script into all frames in the active tab.
    chrome.extension.sendRequest(links);
    
    // Download all visible checked links.
    chrome.experimental.downloads.download({
        url: visibleLinks[i]},
        function(id) {
    });
    

    And, of course, here's a program called SingleFile which, as an extension. It seems to do just what you're after (or you could download just the parts it's comprised of separately):

    SingleFile (c) 2011 Gildas Lormeau

    SingleFile is a Chrome extension that helps to archive a complete page into a single HTML file.

    The bad news I'm afraid that quite lot of that is useful, since now that I've looked at a lot of it and other resources, I think quite a bit of this is more or less internal browser only. Pay attention to the example apps, and keep in mind there are several different kinds of apps with different uses and levels of access.

    Needless to say, I found a whole lot of stuff, and I have no idea how much of it you want, need or care about. But I figured since you got me thinking about it again, I'd go ahead and share with you what I found. There's several example apps I think you could reconfigure or work with to get to work for you. Good luck.


    Some other highlights:

    • OptionsPage, which seems to be how the browser interacts with chrome.tab
    • filer.js, an HTML5 File API class for Chrome
    • Chrome App Samples @GitGub, including a Filesystem Access Example
    • Another sample extensions repository
    • Hello World
    • document.getElementsByTagName('html')[0].innerHTML on window.load
    • chrome.tabs
    • Content Scripts is most likely what you need, along with...
    • Programmatic injection and
    • Communication with the embedding page
    • The Dev Tools source page
    • chrome / browser / resources,
    • chrome.* APIs
    • chrome / browser / resources / file_manager / js
    • chrome-toolbox
    • chrome / browser / resources / extensions
    0 讨论(0)
  • 2020-12-11 14:11

    I would suggest to load the document you want to open in the popup and extract it's innerHTML like this:

    var popup = window.open('http://url.com');
    // documentElement is the <html> element so you would get everything inside
    var source = popup.document.documentElement.innerHTML;
    

    This works on IE. I am not exactly sure what Chrome's restrictions for cross-domain popups is so you may have to check your local settings for that.

    0 讨论(0)
提交回复
热议问题