Detect Chrome Extension background page console opened - javascript

Just like the title says, I'm wondering whether it's possible to detect when I click on "Background Page" for my test plugin on the "chrome://extensions/" page.
Right now when I open the background page, the console is undocked. I saw this post and found ways to make it work inside each content script. But is there a way to make the plugin detect it's own console opening?
This function from that post inside my background.js doesn't seem to detect anything.
chrome.tabs.query({url:'chrome-devtools://*/*'}, function(tabs){
if (tabs.length > 0){
console.log('opened');
}
});
Any advice would be highly appreciated.

Devtools windows are not visible to tabs/windows APIs anymore.
This has changed since the answer from '14 was posted - therefore this method no longer applies.
Unfortunately, I can't find a link to the Chromium issue that implemented that.

Related

How DO I disable minimize, maximize button in the browser?

'm trying to make an application for chrome and I have the manifest file background.js and then the window.html. I'm trying to disable/remove the maximize/minimize button where it says x on the top of the right hand side of the page but I'm doing it for a chrome application . How do I disable it so people cant change the size of it? Code is needed tried looking for code and myself but couldn't find anything. Would be amazing if you could I know stack overflow is see code and get better code but I don't know any code for this please help me I'm desperate! thanks!
This is a browser limitation - you can't do this. Malicious actions like these are disabled by browsers.
However, you can open a window without a toolbar or menubar:
window.open("mypage.html","mywindowname", "toolbar=no,menubar=no");
Check out this reference for more information on window.open.

Chrome to read when window is focused,aka opened

I am still fairly new at programing. I have played around with JavaScript before, but it is still tricky for me.
I got this great idea for an extension for Google Chrome- in the future it would be nice to port it into other browsers. For now I think Google Chrome would be the easiest way to develop for.
I investigated a little and finished the kitties tutorial on the extensions site.
From there it makes sense- easy for the most part, but my idea sounds impossible to me. Simply, the extension would automatically reload the browser when window is selected or focused on the screen. Saves time by not pressing Ctrl+R (PC), or Cmd+R (Mac), or reload button every time the developer checks an update on code.
I was reading through the API documentation and found the method
chrome.browserAction.onClick, is there like chrome.browserAction.focused? Is this idea even feasible?
I also have to take in consideration that Chrome is visited by multiple OS. I wonder if Mac OS, Linux, and Windows version need different JavaScript instruction to pull this off? This simple idea is overwhelming...
Thanks for input in advance :)
Sounds like you'll want to use chrome.windows.onFocusChanged:
Fired when the currently focused window changes. Will be chrome.windows.WINDOW_ID_NONE if all chrome windows have lost focus. Note: On some Linux window managers, WINDOW_ID_NONE will always be sent immediately preceding a switch from one chrome window to another.
Here's an example of how to reload a newly-focused window's active tab:
chrome.windows.onFocusChanged.addListener(function(windowId) {
if (windowId != chrome.windows.WINDOW_ID_NONE) {
chrome.tabs.query({ active:true, windowId:windowId }, function(tabs) {
if (tabs.length == 1) {
var tab = tabs[0];
chrome.tabs.reload(tab.id);
}
});
}
});
You'll also need to declare the tabs permission in your manifest.

Firebug Lite on Chrome causes Footer Issue, is there a fix?

I'm a Chrome user and would be lost without Firebug, but one issue has always annoyed me. Namely, the fact that the Firebug console doesn't appear below the site you're viewing (ie the way it behaves in Firefox). Instead, the console sits above the site, obscuring the footer and content. It's a little thing but annoying all the same.
I understand that this is because of the way Google restricts Chrome extensions but is there a way around this particular issue?
I haven't found a solution anywhere. So, with some help from other stack overflow threads, I came up with a very simple function and as I couldn't find much about this, I thought I'd post it here for anyone with the issue.
I'm not a JavaScript programmer, but I do use jQuery. As such, I run this inside jQuery's ready method. Once the site has loaded, it'll check to see if Fire bug is open, if so, it simply adds a 400px bottom margin to the body. Obviously, if your console is bigger/small than that, just change the size inside the jQuery code.
It won't however change anything if you open the site and then open Firebug. It's nothing major, just open Firebug then refresh the page an it'll work.
// add body margin if firebug is open
if (console.log.toString().indexOf('apply') != -1 && navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
$('body').css('margin-bottom', '400px');
}
Hopefully this will be of use to somebody.
EDIT:
WARNING: This can possibly cause your jQuery to stop working in Internet Explorer. So, just remove this if you find that your jQuery doesn't work.
Instead of modifying your webpage's CSS code which may have adverse effects, you should just detach Firebug Lite in Chrome, then position that popup window under the resized Chrome browser window.
To perform this, just press the center button in the Firebug Lite window located at the top right corner.
Right-click the image below and view in full size if that helps:
Open Image in New Tab / View Image
This way, you'll have two separate areas that don't overlap yet play nicely together.
Per Stan's comment above... about what does Firebug Lite provide extra when compared to native Chrome's Developer Tools, I would have to say it provides familiarity and a great DOM Tab that Chrome lacks.
More importantly thought, you can actually use BOTH consoles at the same time.
This allows easier monitoring of two different panes and with a multi-monitor setup this can be a useful scenario. Even with a large monitor things look good.
Right-click the image below and view in full size if that helps:
Open Image in New Tab / View Image

Popup Window With Specific Size

I am trying to implement a pop-up window similar to how Origin (click on the 'Log In' does it (pops up in another window with a specific size). I've tried going through their code but I cannot find out how they are doing it. I tried Googling this issue and someone said to use window.open, but I cannot find on the Origin website any reference to this code. I've also noticed that the when viewing the Origin website on IE, clicking the 'Log In' link will open the page in the same window as oppose to popping up another window. Is there some sort of IE detection going on? Why would Origin do that only for IE?
They could be using window.open in an external JS file. Basically, they use that to open up a login page and saves all the login stuff in what is called PHP Sessions.
It might not work in IE because IE doesn't support a lot of the newer technologies that are being used right now. Honestly, it's better to make the login page on the same window, because some browsers might disable popups, or some users might just find popup windows annoying.
something like this?
window.open('your page location', 'pop out window's title', 'width=850px,height=600px,top=200px,left=400px,toolbars=no,scrollbars=yes,status=no,resizable=yes');

Chrome & PopUp window names

I am opening pop up windows from a website (flash content) the following way:
RING = window.open(path,'RING_Projekt','width=800,height=600,scrollbars=no,top=' + t + ',left=' + l +'');
The HTML file opened in the popup is valid HTML with a <title>, yet Chrome (all other browsers do work fine) will display "Untitled" in the title bar.
Does anyone know why this is happening and if there is an error / workaround that could fix this? Or is this some kind of a pop up blocker malfunction / bug?
Thanks!
EDIT: Playing around, I noticed the following (unfortunately it ADDS to my confusion...): the page with the flash content opens another popup (displaying news) on load by doing:
var NEWS = window.open('popup/news.htm','RING_news','width=400,height=400,scrollbars=no,top=20, left=20');
When I now open a popup with the function mentioned in the above post, then go and close the news-Popup opened on load and then switch back to the "on-click"-Popup the popup magically acquired a name. When you close this and open it again, the name is gone again.
To be honest: I don't get it. I should be able to have more than one pop-up, right? Also, I cannot see any naming problems or anything else that could explain this behavior.
Am I missing something big here? Or is this a plain bug?
Ok, I am a 99.99% sure this is a Chrome bug, so I'll answer this myself.
Chrome seems to read the specified title correctly from the HTML (as it will be displayed in the task bar), but seems to have problems when having to display the name in the bar on the popup (see screenshot below). When you start to fiddle with the popup (move / resize), the title will sometimes appear and disappear again. Yet, the names in the task bar will always be right (that plus the fact that it works in every other browser lets me think it is a bug).
I am running Chrome 14.0.835.186 m on Windows Vista.
http://code.google.com/p/chromium/issues/detail?id=113201
its a open bug
This is a bug with Chrome. However, there is a workaround for this.
If you put the following script in the page that opens in the popup window, it seems to work fine.
<script language"text/javascript">this.window.resizeBy(1,1);this.window.resizeBy(-1,-1);</script>
The second argument to window.open isn't the <title> of the new window, used by <a target="...">, for example.. The title is determined by the content of the page.
See MDN docs for more info.

Categories

Resources