Hello Team I need to add this code to a puppeteer test to listen in the page that I'm working the messages that the page which is opened automatically
window.addEventListener('message', event => {
console.log(event
});
I Try to use this code https://github.com/puppeteer/puppeteer/blob/main/examples/custom-event.js but this is not suitable for me. Any idea?
Thanks
Related
I'm trying to do something when a web browser has loaded a new web page.
my code in background.js is here.
chrome.history.onVisited.addListener(function(details) {
console.log('onVisited is fired: '+details.url);
});
Unfortunately, console outputs 'onVisited is fired: xxxxx' multiple times per a single event.
help me. plz.
I followed this guide from the Forge Community Blog.
The blog suggests loading an iFrame with the src attribute set to https://accounts.autodesk.com/Authentication/LogOut
<iframe src="https://accounts.autodesk.com/Authentication/LogOut" />
Though the iFrame loads properly, the user does not get logged out of the Forge platform.
This method worked well until sometime this past week or so. Now, the user remains logged in.
However, manually opening a new window and navigating to the LogOut URL does log the user out.
This appears to be a new change but I cannot find any documentation for it.
I used this in the past and so far I have not encountered any issue, basically goes to the Nodejs SDK to use the endpoint for sign out.
// prepare sign out
$('#signOut').click(function () {
$('#hiddenFrame').on('load', function (event) {
location.href = '/api/forge/oauth/signout';
});
$('#hiddenFrame').attr('src', 'https://accounts.autodesk.com/Authentication/LogOut');
// learn more about this signout iframe at
// https://forge.autodesk.com/blog/log-out-forge
})
To solve this, I decided to open a temporary new window for the logout url. I'm not happy with the solution, but it functions.
const newWindow = open('https://accounts.autodesk.com/Authentication/LogOut');
setTimeout(() => newWindow.close(), 500);
I just found Framework7 and it looks promising as a base for mobile apps.
From navigation tabs I can load a Component Page which has dynamic data. But this data is only set when the application is loaded.
Wanted:
Every time user clicks on tab, load data and render page.
Question:
How can I make a component page load every time?
I have made an example from framework7-template-tabs. Check console showing when pageInit is called.
Live:
http://f7-navigate-component-question.surge.sh/
Code:
https://github.com/gotling/framework7-tab-component-page-question
If you want some action to happen every time a particular tab is clicked/loaded, you can use the show event of the tab, documented here.
For example, to alert something every time tab2 is loaded, you could do this
$$("#tab2" ).on( "show", function( event, ui ) {
myApp.alert("Tab loaded!");
} );
I got the answer in the Framework 7 forum.
Listen to page show events:
$('#view-catalog').on('tab:show', ...
Refresh the page:
$('#view-catalog').on('tab:show', function () {
catalogView.router.navigate(catalogView.router.currentRoute.url, {
reloadCurrent: true,
ignoreCache: true
});
});
If using Framework7 2.0.6 or newer that could have been simplified with:
$('#view-catalog').on('tab:show', function () {
viewCatalog.router.refreshPage();
});
I have an electron app, and would like to fire off an event every time the app is in focus. For example, if I have my electron app and chrome open, and I switch to chrome, then back to electron, I want that event to fire. Any ideas?
Thank you.
There is the focus event for this.
In your BrowserWindow you have to:
const {BrowserWindow} = require('electron')
let win = new BrowserWindow()
win.on('focus', () => {
//do something
})
REF: https://github.com/electron/electron/blob/master/docs/api/browser-window.md
I've made an extension who's purpose is to redirect urls.
I.e: www.google.com becomes: www.mysite.com/?url=www.google.com
I came across this post:
How to modify current url location in chrome via extensions
The problem I'm having is that the url's are both processed. The tab initially loads up google.com and only after it's finished my request is shown ( www.mysite.com/?url=www.google.com).
Is there any way to stop the initial request from being processed?
Something like:
chrome.tabs.onUpdated.addListener(function(tabId,obj,tab){
update.stop() // ??????????? Here I'm missing...
chrome.tabs.update(tabId,{url:....}, function callback); // My update stuff..
});
Thoughts?
thank you all.
You're looking for the webNavigation API.
You can register listeners to handle user navigation by modifying or blocking the request on the fly.
In the example below, when a user navigate to www.google.com, before the page even start loading onBeforeNavigate is fired and you can redirect the user to the CSS validation page for that URL:
chrome.webNavigation.onBeforeNavigate.addListener((details) => {
if(details.url.indexOf("www.google.com") !== -1)) {
chrome.tabs.update(details.tabId, {
url: "https://jigsaw.w3.org/css-validator/validator?uri=" + details.url
});
}
});
Remember to add the "webNavigation" permission to your extension manifest to get this functionality enabled.
chrome.tabs.onUpdated is fired two times per tab load - once a tab starts loading, and another time when it finishes loading. If you attach your update to the tab start loading event then it should work relatively quickly. You will still see original url being loaded for a brief moment, but it won't wait until it finishes, as you are describing.
chrome.tabs.onUpdated.addListener(function(tabId,obj,tab){
if(obj.status == "loading") {
chrome.tabs.update(tabId,{url:....}, function callback);
}
});
I don't think there is a more efficient solution at the moment.