|
'use strict'; |
|
/** |
|
* @usage node sharepoint.screengrab.js url filename.ext |
|
*/ |
|
|
|
var args = process.argv.slice(2); |
|
|
|
const puppeteer = require('puppeteer'); |
|
|
|
puppeteer.launch().then(function (browser) |
|
{ |
|
try |
|
{ |
|
const options = { |
|
path: args[1], |
|
fullPage: true |
|
} |
|
const headers = new Map(); |
|
headers.set( |
|
'Proxy-Authorization' |
|
); |
|
const viewPort = { |
|
width: 1280, |
|
height: 800 |
|
} |
|
browser.newPage().then(function (page) |
|
{ |
|
page.setViewport(viewPort) |
|
page.setExtraHTTPHeaders(headers); |
|
//TODO: Authenticate Here |
|
try |
|
{ |
|
page.goto(args[0]) |
|
page.waitForNavigation( |
|
{ |
|
waitUntil: "networkidle0" |
|
}).then(function () |
|
{ |
|
page.evaluate(function () |
|
{ |
|
var css = 'textarea{white-space: pre-line !important;}', |
|
head = document.head || document.getElementsByTagName('head')[0], |
|
style = document.createElement('style'); |
|
|
|
style.type = 'text/css'; |
|
|
|
if (style.styleSheet) |
|
{ |
|
style.styleSheet.cssText = css; |
|
} |
|
else |
|
{ |
|
style.appendChild(document.createTextNode(css)); |
|
} |
|
head.appendChild(style); |
|
var noscript = document.getElementsByTagName('noscript'); |
|
var index = noscript.length; |
|
while (index--) |
|
{ |
|
noscript[index].parentNode.removeChild(noscript[index]); |
|
} |
|
var script = document.getElementsByTagName('script'); |
|
var index = script.length; |
|
while (index--) |
|
{ |
|
script[index].parentNode.removeChild(script[index]); |
|
} |
|
var notDlg = document.getElementsByClassName('s4-notdlg'), |
|
i; |
|
for (var i = 0; i < notDlg.length; i++) |
|
{ |
|
notDlg[i].style.display = 'none'; |
|
} |
|
var ribbonrow = document.getElementById("s4-ribbonrow") |
|
if (ribbonrow) |
|
{ |
|
ribbonrow.style.display = 'none'; |
|
}; |
|
var leftpanel = document.getElementById("s4-leftpanel-content") |
|
if (leftpanel) |
|
{ |
|
leftpanel.style.display = 'none'; |
|
}; |
|
return document.documentElement.innerHTML; |
|
}).then(function (bb) |
|
{ |
|
setTimeout(function () |
|
{ |
|
page.$("[id$='XmlFormView'] table").then(function (clipObj) |
|
{ |
|
if (clipObj) |
|
{ |
|
console.log("Clip Obj Found") |
|
options.fullPage = false |
|
clipObj.boundingBox().then(function (boundingBox) |
|
{ |
|
options.clip = boundingBox |
|
clipObj.screenshot(options).then(function () |
|
{ |
|
browser.close() |
|
}) |
|
}) |
|
} |
|
else |
|
{ |
|
console.log("Clip Obj NOT Found") |
|
page.screenshot(options).then(function () |
|
{ |
|
browser.close() |
|
}) |
|
}; |
|
}, 2000); |
|
}) |
|
}) |
|
}) |
|
} |
|
catch (e) |
|
{ |
|
console.log("Clip Obj NOT Found") |
|
browser.close() |
|
process.exit() |
|
} |
|
}) |
|
} |
|
catch (e) |
|
{ |
|
console.log(e) |
|
browser.close() |
|
process.exit() |
|
} |
|
}) |