I wrote a chrome extension for test devetools .But I couldn't get the content of the request.
The followiing is my code:
chrome.devtools.network.onRequestFinished.addListener(
function(request) {
if(request.request.url==='https://www.google.com/'){
request.getContent((content,encoding)=>{
chrome.devtools.inspectedWindow.eval(
'console.log("url address: " + unescape("' +
escape(request.request.url) + '"))');
chrome.devtools.inspectedWindow.eval('console.log("content:'+ content+' ")');
chrome.devtools.inspectedWindow.eval('console.log("start console log content: ")');
chrome.devtools.inspectedWindow.eval('console.log("encoding:'+encoding+' ")');
chrome.devtools.inspectedWindow.eval('console.log("end console log content:")');
});
}
}
);
chrome.devtools.panels.create('Osudio', null, 'panel.html', null);
The following is my screenhot. (We can see the content can be inspected in the watch)
I think this problem is affected by the "potentially encoded" .
I hope someone can help me .I'm already crazy.
Related
Although it may be a duplicate question but I have done everything I can without getting the solution.
I'm using Node + Express.
We use to send link of PDF file as CDN url in SMS
The link looks like this:
/api/v1/cdn/pdf/24
To get PDf and return, I have this code:
let parameter = await this.parameterDB.readRecord(where);
if (parameter) {
let fileName = parameter.id + '_' + parameter.patient_id + '.pdf';
// METHOD 1
let data = fs.readFileSync(constants.PATH.PDFS + fileName);
res.setHeader('Content-disposition', 'inline; filename="' + fileName + '"');
res.contentType('application/pdf');
res.send(data);
// METHOD 2
res.writeHead(200, {
'Content-Type': 'application/pdf',
'Content-Disposition': 'inline; filename=report_' + fileName,
'Content-Length': data.length
});
res.end(data, 'binary');
// METHOD 3
let file = fs.createReadStream(constants.PATH.PDFS + fileName);
var stat = fs.statSync(constants.PATH.PDFS + fileName);
res.setHeader('Content-Length', stat.size);
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', 'inline; filename=' + fileName);
file.pipe(res);
} else {
return this.responseUtil.sendReadResponse(req, res, {
message: 'not found'
}, 200);
}
I all of the above 3 methods, when I click on the link in SMS, it downloads the PDF file instead of opening in web browser (which is annoying for the customers).
File is returned properly.
What can I do here?
I assume, by sending the API link in SMS means you want your customers to view the PDF in mobile browser.
Browsers can view the PDF file due to the plugins they support or have installed by default, but this is not the case with phone browsers, atleast
not all browsers on smartphones support PDF viewer, especially android. I can view PDF files in safari and chrome browser on iPhone though, because they have support for PDF view.
source: https://www.quora.com/Why-does-Chrome-on-Android-not-open-PDF-files-like-Chrome-on-Windows-Linux-can
Any one of the method in your code can show the PDF file on desktop browser with no modification, however when you try to call the API URI on phone browser,
you'll see the PDF file getting downloaded as there is no support for that in the browser, instead browser looks for the native application on phone,
downloads the file and opens in it.
Although there is a way/work-around for this if you want to see the PDF files in the browser using google docs.
You can simply embed your URL location of the PDF in the google docs link itself and redirect to it when customer hits your API URI.
source: How to display a PDF via Android web browser without "downloading" first
So you can modify your code something like this:
let parameter = await this.parameterDB.readRecord(where);
if (parameter) {
res.redirect("https://docs.google.com/gview?embedded=true&url=http://host...your-pdf-path.pdf")
} else {
return this.responseUtil.sendReadResponse(req, res, {
message: 'not found'
}, 200);
}
There is an another alternative for this, although it would require more efforts, but it is worth if you have lots of documents in your application that need to be seen on phone browser.
You can make use of PDF.js by Mozilla and create your own custom pdf viewer, this viewer is completely created in vanilla JavaScript and thus, it is supported by almost all browsers.
Once you have your own viewer implemented, all you have to do is :
res.sendfFile('show an html file eg index.html', { pdfURL: <path of the pdf file> });
and inside this index.html file you need to pass the path of the pdf file, make use of PDF.js functions to get the document data and create custom viewer.
You can use ejs to achieve this in Express JS.
I have a Chrome extension (https://chrome.google.com/webstore/detail/apsic-xbench-extension-fo/nhadbgflnognogbicnbeepnbpehlocgc) that suddenly stopped working right after the Chrome 73 update.
The symptom is that if I go to the page where the extension is designed to work (https://translate.google.com/toolkit) and I click on the extension icon, instead of running the background page code, the pop-up menu for the extension appears (as if I had right-clicked the icon).
However, if I load the exact same code locally (not from the store), the Chrome extension runs fine.
The background page console for the extension loaded from the store does not seem to issue any error. If I place a breakpoint for the first line in the onClicked listener for the page action, it does not stop there for the Chrome store extension (and the breakpoint works fine for the extension loaded locally).
Why do I get different behaviors if I load the extension from the Chrome store or I load it locally?
In Chrome 72, the extension worked fine.
Answering own question: I tracked down the issue. It turned out that if the Chrome extension was installed from the Chrome store using Chrome 72, then it did not work right after the update to Chrome 73.
However, if after Chrome 73 is updated, you remove the extension and add it again from the Chrome store, then the Chrome extension works again. Strange but true.
Chrome 73 inject some new security. Just try to move your xHTTP requests to your background script with chrome.runtime.sendMessage and get response with SendResponse callback.
In content or popup script replace ajax with :
chrome.runtime.sendMessage(
{ action: "check", data: {/* params for url */}},
// callback with url response
function(response) {
if( response.success ) {
var myDataFromUrl = response.data;
...
} else {
console.log('Error with `check`,', response.data);
}
}
);
From background script:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
var url = 'https://mysyte.com/';
if(request.action === 'check' ) {
url = url + 'check'
ajax( url, request.data,
success: function( d ) {
sendResponse({success: true, data: d});
},
error : function( d ) {
sendResponse({success: false, data: d});
}
);
}
});
function ajax( url, params, cbSuccess, cbError ) { ... }
I'm trying to generate report with cucumber-html-reporter. On it's GitHub page I saw a fancy bootstrap report, where a screenshot is attached to the failed step itself.
https://www.npmjs.com/package/cucumber-html-reporter
I'm working with cucumber-js 2.3.1 and cannot attach a screenshot to the StepResult.
I can attach a screenshot only in the After hook, where the World is available.
After(function (scenario) {
if (scenario.isFailed()) {
const world = this;
return browser.takeScreenshot().then(function (screenShot) {
world.attach(screenShot, 'image/png');
});
}
});
This is working fine, but unfortunately the screenshot is attached to the "After" step, not to the failed one.
I have tried this:
registerHandler('StepResult', function (StepResult) {
if (StepResult.isFailed()) {
return browser.takeScreenshot().then(function (screenShot) {
var decodedImage = new Buffer(screenShot, 'base64');
StepResult.attachments.push({
data: decodedImage.toString('base64'),
mimeType: 'image/png'
});
});
}
});
It works, the attachment is added, but not rendered into the report, since the cucumber json_formatter.handleStepResult is executed BEFORE the 'StepResult' hook is invoked.
Can someone show me a solution?
Thanks!
The reporter would show the Screenshot link in the failed STEP if you capture screenshot in the STEP itself. If you capture at the AFTER hook, it will show in the hook.
On the example shown in the Github page, it attaches the screenshot to the Step, and so it shows to the "then" step. Please take a look at here for more info.
I have a script to test that - on click - generates an iFrame which downloads a file. How can I intercept the response with CasperJS?
I already tried the sequence:
casper.click('element');
casper.withFrame('frame', function(){
console.log(this.getCurrentUrl()); // only return about:blank, but should have URL
console.log("content: " + this.getHTML()); // Yep, empty HMTL
this.on('resource.received', function(resource){
console.log(resource.url); // never executed
});
});
I need the content of the file but can not really produce the URL without clicking the element or changing the script I'm testing.
Ideas?
I tried other events, but none got fired when downloading via the iframe. I found another solution that works - but if you have something better, I'd like to try it.
Here it comes:
// Check downloaded File
.then(function(){
// Fetch URL via internals
var url = this.evaluate(function(){
return $('__saveReportFrame').src; // JavaScript function in the page
});
var file = fs.absolute('plaintext.txt');
this.download(url, file);
var fileString = fs.read(file);
// Whatever test you want to make
test.assert(fileString.match(/STRING/g) !== null, 'Downloaded File is good');
})
I have to load XML from external domain, so my code looks like this
var loader:URLLoader = new URLLoader();
configureListeners(loader);
var request:URLRequest = new URLRequest("http://demo.softsolutions4u.com/ss4uplayer/modules/podcast/lib/PlayerAPI.php");
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
}
function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
trace("completeHandler: " + loader.data);
datas.appendText("completeHandler: " +loader.data);
}
function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
datas.appendText("securityErrorHandler: " +event);
}
But it throws exception at run time
securityErrorHandler: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048: Security sandbox violation: http://192.168.2.55/onlinemovie/Development/SS4UPlayer310310/test.swf cannot load data from http://demo.softsolutions4u.com/ss4uplayer/modules/podcast/lib/PlayerAPI.php."
Crossdomain XML file also loaded and security allodomain is in(*).
Please tell me what I missed here.
its not like that. We are not going to use the flash swf file, but our 'N' no of clients going to use this swf in their server, so then in that case how could i place the crossdomain.xml. I dont know where i should put it. Please help me to fix it.
Try adding this line
Security.allowInsecureDomain("demo.softsolutions4u.com");
You should be able to test the movie ONLY inside the Flash IDE or on the client server
I don't see crossdomain.xml at the location http://demo.softsolutions4u.com/crossdomain.xml, it returns a 404 error. You should place the crossdomain.xml at the root of the domain and try again.