I'm using puppeteer for my E2E testing on Linux/Mac. Works like a charm, but for debugging purposes I would like to use DevTools. I start the browser as follows
const browser = await puppeteer.launch({
ignoreHTTPSErrors: true,
headless: false,
devtools: true,
dumpio: true,
args: [
`--disable-extensions-except=${EXTENSION_PATH}`,
`--load-extension=${EXTENSION_PATH}`,
'--user-agent=PuppeteerAgent',
'--disable-infobars',
'--no-sandbox',
'--disable-setuid-sandbox',
],
...(slowMo && { slowMo }),
});
Unfortunate, dumpio doesn't seem to do much, I expected to see my console.log messages in the terminal (but maybe it is not supposed to do this). But anyway, what would really help me is if I could open DevTools (which I already can) but instead of selecting the Element tab I would like top open by default the Console tab. Is something like this possible?
Something that would be nice too, is to enable Preserve log!
Related
I have the following code (I don't recommend running it):
let req = new XMLHttpRequest();
req.open('GET', 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + token);
req.onload = function() {
console.log('response:', req.response);
};
req.send();
What happens is this opens up a new tab, and this tab completely steals all the focus. I can't use any of the other Chrome tabs, it quickly switches back to the auth tab. And if I log-in with the auth tab, it just reloads the same auth tab, and I am back to square one.
The token is acquired via this call:
chrome.identity.getAuthToken({interactive: true}, function (token) {}):
Has anyone seen this horrible problem? I can't get Chrome to stop making an auth request to the url in the screenshot. It keeps stealing the focus, and forcing me to login over and over again.
From what I can tell, it's actually this call this brings to me to the black hole authentication tab:
chrome.identity.getAuthToken()
This didn't use to happen, but seems like it started happening after I added this to my manifest.json file:
"oauth2": {
"client_id": "5461xxx462-7gebv033e9csxxxxg5f6ggu22rju9374.apps.googleusercontent.com",
"scopes": [
"https://www.googleapis.com/oauth2/v1/userinfo", // added this line
"https://www.googleapis.com/oauth2/v1/userinfo.picture", // and added this line
"https://www.googleapis.com/auth/chromewebstore.readonly"
]
},
The old login screen looks like this, and this worked really nicely:
I am currently fairly certain that these two lines in the scopes array are what are causing the problem:
"https://www.googleapis.com/oauth2/v1/userinfo"
"https://www.googleapis.com/oauth2/v1/userinfo.picture"
what do I do?
I've had this problem before but it was months ago. If I recall correctly, it ended up being that the client_id was invalid. Double check your oauth client_id to make sure you're using the correct one.
I'm making a chrome extension and using page_action instead of browser_action because I need this extension for only one specific url. I'm using declerativeContent for activating the page_action;
// When the extension is installed or upgraded ...
chrome.runtime.onInstalled.addListener(function() {
// Replace all rules ...
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
// With a new rule ...
chrome.declarativeContent.onPageChanged.addRules([
{
// That fires when a page's URL contains ...
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: 'www.example.com', schemes: ['https'] },
})
],
// And shows the extension's page action.
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
});
});
In normal tabs of chrome, there is no problem. Page_action works exactly the way I want. But in pop-up windows, there is a problem. I mean, there is page that contains links to pop-up pages. When I click to them, pop-up windows open but I can't see the page_actions in the address bar.
What could be the problem?
Unfortunately, Google Chrome extensions doesn't provide page_action icon on the adress bar in pop-up windows. But still, extension works on that window. You should think other ways to make your extension functional.
I am writing a chrome extension which refreshes pages after a certain time interval. I got it working fine, but a new problem occurred..
Whenever the page refreshes the tab gets highlighted (starts blinking) or else comes in focus. Ie it is getting focused on.
Now this works differently depending on the chrome browser state, but the core issue is the same:
1. If user switches tab to another one (suppose writing an email in gmail.com) while waiting for page to refresh itself, on refresh the current mail tab will get outfocused (so he wont be able to continue writing his email without clicking on the window first)
If the user swithces to any other application on his workspace (like my computer, outlook etc), on refresh the chrome icon will start blinking on the taskbar (highly annoying)
If the user has multiple chrome windows open with a tab each running the refresh code, then on refresh that window will get focus (come at top). This will repeat for all chrome windows whenever there specific refreshes occur.
Steps to reproduce the problem:
Write a simple extension
In the background page, create a new tab with:
chrome.tabs.create({ url: "https://drive.google.com/", active: false})
Now in a loop, after every minute, refresh this tab with:
chrome.tabs.update(tab_id, {url: "https://drive.google.com/",
active: false,
highlighted: false});
Once you start this code, either minimize the chrome window or shift your workspace and focus on something else.
Every time tabs.update() gets called, the Chrome window either unminimizes from task bar, or gets the focus on it.
What i want is to remove this focus whenever the page refreshes.
If anyone can please help me with this i would be very greatful.
Thanks,
Umair
EDIT:
code for my background.js file
chrome.webNavigation.onErrorOccurred.addListener(function (_errorDetails) {
var myUrl = 'myPage.htm';
chrome.tabs.update(_errorDetails.tabId, { url: myUrl, active: false,
highlighted: false, selected: false },
function (_tabDetails) {
chrome.windows.update(_tabDetails.windowId, { drawAttention: false });
});
});
Iv tried to make all related parameters false to stop focus.
Also on myPage.htm the function reload() is called on pageload.
function reloadPage() {
//code for 10 second delay
location.reload();
}
myPage.htm is itself a simple page showing few lines of text like 'Unable to load page' etc.
I changed the code and got it working for me as per my requirements.
What i did was instead of using the reload function to refresh page, i used the message passing technique of the chrome extension to send a message (containing url and tabID) from my js to background.js and update the relevant tab there with the url.
I know this is not a perfect solution, but it worked for me, therefore im sharing it.
I am a newbie for Google Chrome Extensions development ,I wonder how to get a reference to the current tab of current window .
I used chrome.tabs.query({'active': true} but it doesn't work when multiple windows opened .
Every window that has a tab has one active tab, so if there are multiple windows open, you need to specify which window you want.
To get the window that the current script is calling from, use:
chrome.tabs.query({ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT }, function (tabs) {
// Do something with tabs
});
If, however, by "current window", you mean the front-most focused window shown to the user, use:
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
// Do something with tabs
});
For further info, see chrome.tabs.query and Chrome's definition of current window.
I have an extension that needs to know what URL is on the active tab, but the problem is that when I open a second chrome window there are 2 active tabs, in the webmaster tools it doesn't give me any indication of what window I'm actually on.
I was actually on the 2nd window when I took this screenshot.
The code that I am using is:
chrome.tabs.query({'active': true}, function (tabs) {
app.tabInfo = tabs[0];
});
But the good code would have been app.tabInfo = tabs[1]; but I need to know that I need to pick that one. So how can I know?
Thank you.
Make your query to select the last focused Window:
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
//...
});
Note: Better don't take currentWindow: true because:
The current window is the window that contains the code that is currently executing. It's important to realize that this can be different from the topmost or focused window.
Source: http://developer.chrome.com/extensions/windows.html#current-window
Use chrome.windows.getCurrent() (or .getLastFocused(), right below it) to get the current window, then look for the active tab in the tabs property of the returned window.