Issue with javascript in Chrome window created by extension - google-chrome-extension

I have a Chrome extension that creates a new Chrome window and loads a URL in the newly created window.
This works as expected, but the URL that is being loaded in the new window is seeing errors that prevent the Javascript on the page from executing. The same URL works without any errors when loaded in a Chrome window created manually.
I have tried loading the URL in a regular Chrome window and in a Chrome window created programmatically by my Chrome extension. I have also removed ALL other functionality from the Chrome extension to verify that our Chrome extension does not have any other impact.
Here is how I'm creating the new window and loading the URL:
chrome.windows.create({
url: 'https://...',
type: 'normal',
top: 0,
left: 0,
width: window.screen.width || 1000,
height: window.screen.height || 600
}, function(newWindow) {
The URL should load exactly the same whether manually by pasting the URL in a Chrome window created by going to File > New Window and those created programmatically via a Chrome extension.
What is the difference between the Chrome windows created by going to File > New Window and those created programmatically via a Chrome extension? What might cause the URL to load or execute Javascript differently in windows created by the Chrome extension?

Related

neutralinojs - how to load browser extension when starting chrome mode?

I have a web page and custom extension that goes with it. The extension is a normal browser extension - not a neutralinojs extension. I can load my extension from the command line (without neutrinojs) with chrome and msedge using the --load-extension=<path-to-extension> option. Extension and page work fine.
I'm having difficulty figuring out how to achieve the same thing with neutralinojs.
I've tried passing the option via the neutralino.config.json config file [example below] and starting the page with neu run. The page loads, but the extension isn't loaded. Near the top of the JSON file, I specify "chrome" as the mode. I'm certain it is starting chrome.
"chrome": {
"width": 500,
"height": 700,
"args": "--load-extension=C:\\project\\my-extension",
"nativeBlockList": [
"filesystem.*",
"os.*"
]
}
I also tried a more direct approach with neutralino-win_x64.exe --chrome-args="--load-extension=C:\project\my-extension". It seems the JSON file isn't read in when I try it this way, and it's not clear to me how to format the other options that need to be passed to it.
How should I go about getting my custom extension loaded when starting in chrome mode? And could I also get neutralinojs to start with msedge instead of chrome with additional chrome options passed to it.

Chrome.windows.onCreated in background script wont recognize browsers first opening

I need to call some method on opening browser from background page in my chrome extension. It works for me on my pc and chrome, but on some other pc's and same version chrome not working. Working only if second browser is opened. Somehow that chrome's api dont see first browser is opened.
Chrome version latest (75.0.3770.90)
chrome.windows.onCreated.addListener((window) => {
this.doSomething(window);
});
function doSomething(window) {
console.log('Window with id: ', window.id, 'opened');
}
I expect to console log every windowId which is opened, but i get only from second opened window.

Chrome Extension Page Action Icon not enabled in Incognito mode but only when installed from Web Store

I have a Chrome Extension Page Action that I wish that users can run both in incognito mode and in regular mode.
The page action open new tabs with:
window.open(url);
I need that the Page Icon opens a new incognito tab if in incognito mode and a regular tab in regular mode. Therefore, I added the following sentence in the manifest:
"incognito": "split",
In the background.js file of the extension, the following code enables the page action:
chrome.runtime.onInstalled.addListener(function() {
// Replace all rules ...
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
// With a new rule ...
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlMatches: '<a_url_pattern>' },
})
],
// And shows the extension's page action.
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
});
});
The page action works fine (the page icon is enabled both in incognito and in non-incognito mode) if I load the extension locally. However, after publishing the extension in the Web Store, the page icon only is enabled in non-incognito mode.
Why do I have this difference in behavior in incognito mode between loading locally or loading the published version from the web store?
BTW, before adding "incognito", "split" in the manifest file, the page icon was enabled both in incognito mode and in normal node in the previous published extension, so it seems that "incognito", "split", which was the only line changed in the extension update has something to do with it.
UPDATE: After further investigation, the mismatch in behavior was not caused by the origin of the extension (i.e. load unpacked vs. web source), but depends on if there is an incognito window open when you click Allow in incognito in chrome://extensions.
It seems that, in split mode, if there is an incognito window open when you click Allow in incognito, the onInstalled listener will be fired both for incognito and non-incognito contexts. However, if there is no incognito window open when you click Allow in incognito, then the onInstalled listener will be only fired in the non-incognito context, so the page action icon will not be enabled in incognito context.
This seems to be a Chrome bug. A workaround for this bug is described in the answer to this SO question.

gulp refresh active tab after code change in chrome extension

I'm developing a chrome extension and I want to automatically refresh the active tab after a code change
I got gulp-open to work so I don't need to navigate to chrome://extensions anymore and manually click "reload"
now only the active tab refresh remains
I've tried gulp-livereload but couldn't get it to work for developing a chrome extension
any ideas how to approach this?
Could you post the code of your chrome extension? Without much info, I hope this is helpful. You can inject the code below to refresh the page after the chrome extension is reloaded:
chrome.tabs.query({
active: true, // Select active tabs
lastFocusedWindow: true // In the current window
}, function(tabs) {
// Since there can only be one active tab in one active window,
// the array has only one element
var tab = tabs[0];
// Javascript to reload the page
var code = 'window.location.reload();';
// Execute the code for the current tab
chrome.tabs.executeScript(tab.id, {code: code});
});

Controlling a web page, casperJS like : can that be done with chrome extension?

I am trying to develop a chrome extension to automtize some tasks on the web (fill form, go to next page, extract data...)
The idea is to develop a kind of http://casperjs.org/ as chrome extension.
I am injecting some JS to an active tab.
JS is run, and everything works fine: problems raise when I navigate to a new url.
When the page navigates to new url (document.location for instantce), the JS stops running since it is unloaded.
My idea would be to store the JS state and resume it once page has loaded:
ex content of source variable: I inject it in background to the web page.
for (i = 0;i < 5;i++) {
document.location = "http://www.example.com/page"+i;
waitUntilPageIsLoaded();
var source = $("body").html();
extractData(source);
}
chrome.tabs.executeScript(null, { code: source });
Of course this does not work since we change the location of the page.
Or more generally speaking, can casperJS can be developped using google chrome extension ?

Resources