Electron webContents.printToPDF doesn't work for webpages containing iframe - iframe

I am trying to convert my webpage to PDF using webContents.printToPDF. Most of the times its working fine but for pages containing iframe which I am using for youtube videos this method doesn't end at all. To update the electron version is impossible for my application. I tried to use webview in the place of iframe which was also not helping. Is there any way to fix this in the same version of electron.
Electron version : 5.0.13
OS: mac OS, Windows
win.webContents.printToPDF({
printBackground: true,
landscape: false,
marginsType: 1,
pageSize
}, (error, data) => {
console.log('Inside printToPDF callback')
if(error) {
showMessage("Unable to export PDF")
return console.log(error.message);
}
fs.writeFile(filePath, data, (err) => {
if (error) {
showMessage("Unable to export PDF")
return console.log(error.message);
}
console.log('Write PDF successfully!');
showMessage(`PDF exported successfully !`);
});
});
For pages containing iframe, the log "Inside printToPDF callback" is never printed.

Related

OpenSeaDragon IIIF Viewer does not work with Manifest json in a NextJS application

Can we make OpenSeaDragon IIIF Viewer work with manifests json? Is Mirador the only option or can we use something else and make OpenSeaDragon work?
I have a manifest.json https://api.bl.uk/metadata/iiif/ark:/81055/vdc_00000004216E/manifest.json and I am trying to use OpenSeaDragon to view it, but it gives me error "No TileSource was able to open".
const source = new TileSource({
url: imageUrl1
})
source && source.addHandler('ready', (event) => {
const viewer = new Viewer({
element: imageElementRef.current,
prefixUrl: '//openseadragon.github.io/openseadragon/images/',
tileSources: [event.tileSource],
showRotationControl: false
})
})

How to have Cypress go through every page on site to see if there are any console errors and if so, make it known to the user running the test

I want Cypress to go through every page to see on a website to see if there are any console errors and if so, make it known to the user running the test. (I'm thinking it would be useful for CSP checking to see if the site is throwing a console error because of a domain not being whitelisted.)
This package cypress-fail-on-console-error
may make it easier
test
import failOnConsoleError from 'cypress-fail-on-console-error';
failOnConsoleError();
const pages = [ "/page1", "/page2" ]
pages.forEach(page => {
it(`verifies the page ${page}`, () => {
cy.visit(page)
})
})
There's some interesting stuff on Cypress and CSP here
Testing Content-Security-Policy using Cypress ... Almost
You can use a combination of Cypress functionality to achieve this. You could store the list of links in an array of strings, use Cypress Lodash to iterate through each string as a separate test, and use the onBeforeLoad callback within cy.visit() to spy on console.error.
describe('Tests', () => {
// Define links
const links = ['/1', '/2', '/3'...]
// Iterate through the links array using Cypress Lodash
Cypress._.times(links.length, (index) => {
it('validates site loads with no errors', () => {
cy.visit(links[index], {
// set the `onBeforeLoad` callback to save errors as 'error'
onBeforeLoad(win) {
cy.stub(win.console, 'error').as('error');
}
});
// Validate error was not called
cy.get('#error').should('not.have.been.called');
});
});
});
A good deal of this answer was taken from this answer.
If you'd like to be specific about the errors that fail, try catching uncaught:exception
Cypress.on('uncaught:exception', (err) => {
if (err.message.includes('Content Security Policy')) {
return true
} else {
return false // only fail on the above message
}
})
describe('Testing Content Security Policy', () => {
const pages = [ "/page1", "/page2" ]
pages.forEach(page => {
it(`visiting page ${page}`, () => {
cy.visit(page)
})
})
})

Deep Link doesn't open the app instead does a google search

I have been using Expo to develop a react-native app, The functionality I am currently trying to implement is to share a link with friends on platforms such as fb messenger/whatapp or even normal texts and when they click this link it will launch my app to a specific page using the parameters.
After extensive research online - I’ve come to a blocker, following expo’s documentation I defined a scheme for my app - when I press share everything works correctly a message is created and I’m able to share content but only as string.
I am using react-natives Share library to share to an app and I’m using Expo to provide me with the link.
Ideally my first goal is to get the app opening using the Expo Link before I explore further into adding more functionality to the link.
Share.share({
message: "Click Here to View More! " + Linking.makeUrl( ' ' , { postkey : "7a5d6w2x9d6s3a28d8d});
url: Linking.makeUrl( ' ' , { pkey : gkey });
title: 'This post is amazing',
})
.then((result) =>{
console.log(result)
if(result === 'dismissedAction'){
return
}
})
.catch((error) => console.log(error))
In the root of my app I have also defined the event handlers: App.js
_handleRedirect=(event)=> {
let {path,queryParams} = Linking.parse(event);
Alert.alert(`queryparams : ${event} path : ${path} `)
this.props.navigation.navigate("Post_Detail",{key:queryParams.postkey})
}
}
componentDidMount() {
let scheme = 'nxet'
Linking.getInitialURL()
.then(url => {
console.log("App.js getInitialURL Triggered")
// this.handleOpenURL({ url });
})
.catch(error => console.error(error));
Linking.addEventListener('url', ({url}) => this._handleRedirect(url));;
}
componentWillUnmount() {
Linking.removeEventListener('url', this.handleOpenURL);
}
When I share the link to Whatsapp, Facebook Messenger or even just messages or notes it appears as myapplink://, I try to enter this into the browser and instead of asking me to open my app - it does a google search.
Please note I am attempting to have this working on Android Device and facing this issue
Is there something I am doing incorrectly?
Any help is much appreciated. Thanks.
You can not open external links, means other than http, https on Android. But you can on iOS. In order to be able to open your expo links, you need proper anchor tags on android. You can create html mails and give it a try, you will see it is gonna work on Android as well.

Auto enable flash for site in asp.net

I'm using Uploadify.swf file to upload certain type of files to my dropbox account. However when the flash is not detected or it is not enabled, the files are not uploaded. As being a developer i have generated a popup message for this issue. But I'm trying to find if there is any way the flash for the site gets enabled automatically, without done manually.
Similarly the swf files is not supported on Firefox. It works fine on Chrome and Internet Explorer.
Below is my code
$(document).ready(function () {
$("#<%=FileUpload1.ClientID%>").uploadify({
swf: 'scripts/uploadify.swf',
uploader: 'Upload.ashx',
cancelImg: 'Content/cancel.png',
auto: true,
multi: true,
method: 'POST',
//fileTypeExts: '*.jpg; *.png; *.gif; *.bmp; *.jpeg; *.JPG; *.pdf; *.doc; *.docx;',
buttonText: 'Upload File',
width: 130,
onUploadSuccess: function (file, data, response) {
console.log("sucess");
console.log(data);
var filName = file.name + Math.random();
console.log(filName);
$("#attachedfiles").append("<tr><td>" + file.name + "</td><td><a onclick=\"deleteHostTable(this);\" href = 'javascript:;'>[x]</a></td></tr>");
},
onFallback: function () {
alert('Flash was not detected or flash version is not supported.');
}
});
});
Firefox and Chrome already disable flash by default. While an end-user still can enable it, flash technology seems to be outdated.
I use a third-party upload component to upload files to Amazon. It also supports DropBox upload out of the box.

Wordpress on iOS requires refresh before uploaded pictures can be seen or viewed

I am launching a wordpress based website which has a custom wordpress open_media window. When I am adding media from iPhone (in Chrome or Safari), I am able to upload pictures from my photo library but they do not show up immediately for use. I get no errors. To find the photo I have to exit out of the media window and refresh my browser then reenter the open media window and the picture will be there.
Has anyone experienced this problem?
function open_media_window() {
var upload = "";
$post_div = $(this).closest('.bizimg-select');
if (this.window === undefined) {
if($(this).hasClass('bizimg-select')){
upload = "bizimg";
}
if($(this).hasClass('vcard-file')){
upload = "vcard";
}
if(upload=='bizimg'||upload==""){
this.window = wp.media({
title: 'Upload my Bizcard Bizimg',
library: {type: 'image/*'},
multiple: false,
button: {text: 'Insert'}
});
}
if((upload=='vcard')){
this.window = wp.media({
title: 'Upload my Bizcard vCard',
library: {type: 'text/x-vcard'},
multiple: false,
button: {text: 'Insert'}
});
}
var self = this;
this.window.on('select', function() {
var files = self.window.state().get('selection').toArray();
var first = files[0].toJSON();
if(upload=='bizimg'){
//do some stuff here
}
if(upload=='vcard'){
//do a bunch of stuff here
}
});
}
this.window.open();
return false;
}
I was mistaken that this issue was restricted to mobile connections only. After much digging and trying to learn more about js backbone and wordpress wp.media (which remains relatively undocumented, by the way), I did figure it out. Using 'image' instead of 'image/*' in the library options allowed the upload to load into the media library screen. 'image/*' was the problem. See below the options that worked for me.
wp.media({
title: 'Upload my Bizcard Bizimg',
library: {type: 'image'},
multiple: false,
button: {text: 'Insert'}
});

Resources