JavaScript emulate window being in focus - javascript

For a project I need to be able to pull data from a minimized tab that displays the Instagram website. Everything works except for the "minimized" part. As soon as the window is minimized, and I refresh the page, there is no image data coming in. This is why I think it is necessary to "trick" the website into thinking that it's onscreen in order for it to load data.
Steps to reproduce:
open https://www.instagram.com/
right-click > Inspect (Developer Tools, please undock for windowed mode)
confirm that the _4rbun elements contain a srcset with the images
minimize Instagram tab
in the console, type location.reload() to reload the page
in dev tools, confirm that there are 0 or 1 _4rbun elements which however don't contain a picture
open the minimized tab
confirm that there are numerous _4rbun elements which all contain links in their srcsets
Similar behavior can be found in the /explore path except that this, on the contrary, at least contains links to the pages displaying the image (but still no direct link to the .jpg)
Is there anything i can do about this? Other websites use things like Store.js to keep track of their data but I couldn't find anything like this in the website's window object so either going the "hacky" focus way or the much cleaner "Store"-kind of way would be fine.
What I've tried was to override hasFocus like the following document.hasFocus = function(){return true}; which does keep the value on true but doesn't seem to affect the website's behavior at all. And I have tried finding an object carrying links etc. but this has been unsuccessful so far, too.

Related

Getting the contents of Chrome's console with JavaScript

First time poster. Currently trying to work on a project but I am having an issue with iframes. I'm making an extension for Chrome, and part of its functionality right now is to be fetching any shapes/borders on a page. Unfortunately, that also includes ones within iframes. I'm currently stuck because I cannot get around security policies from Cross-Domain sources.
I was wondering, however, if it is possible to create a function that displays what the Chrome console does when I hit "inspect element" on a page... I tried to make a console function called "save" that would automatically download a file of anything output to the log, but the output for the iframe's HTML is blank except for its tag...
When I am inspecting an element on the page, I can see the contents of that iframe just fine. Is there anyway to just get the actual text from Inspect Element and store that? I know this may be silly, but I genuinely have no idea. I am pretty new to JavaScript. I just need to match up script tags for shapes for part of the extension's functionality.
I'm assuming that this is going to end up being impossible, but I figured I'd ask. I'm also assuming that this inspect element functionality is something that only the browser can work with. But hey, maybe there's a way. Thanks for any help.

Opening a link in a different browser

I'm trying to find a way to take a link from one browser and open it in another browser. This could be taking a link from a Firefox tab and opening it in Chrome, or taking a link in a Chrome Incognito window and opening it in a non-incognito Chrome window.
Here's some more detail. I have a webpage that refreshes every second, and uses javascript(via Greasemonkey/Tampermonkey) to search for certain keywords. When a keyword in my list matches one associated with a link on the page, it automatically opens that link in a new tab. If it's possible, I need to take those links to a different browser somehow, automatically.
AFAIK, something like this isn't possible with javascript due to security issues. The only two solutions I can think of are:
1: Using AutoHotKey to make a macro to copy the link, alt-tab, and paste into the other program. This is manual, I want something automatic. EDIT: I realized I can use AHK to monitor a page, but I don't know if it could be done without introducing more latency than I would like. Keeping the total time from the webpage refreshing to opening the link as low as possible is the most important thing.
2: Having some other program handle it for me. I'm not aware of any and wonder how difficult/costly it would be to roll my own or have someone make one. I'm not even sure if I could interface it with my current script.
I'm fairly certain it would be possible with number 2, although I don't know about cost or difficulty... could there be another way to accomplish this?
For reference, this is the relevant section of code that I'm currently working with. It opens any link which matches a list of keywords in a new tab. These are the links I'm trying to figure out a way to open in a different browser. It uses dynamic object names and a dynamic URL, but essentially this is just saying if the checkboxes are checked and a link matches my autoOpenList(keyword list), then open the link in a new tab.
if(jQuery.inArray(autoOpenTemp,autoOpenList) != -1 && window['autoAccept' + autoOpenTemp].checked && autoAccept_input.checked ){
var tempURL = LINK_BASE+obj.acc_link;
window.open(tempURL, '_blank');
}
Use Java's HttpServlet Class to create a web application. You can setup the server by Tomcat. Servlets Quick Guide.
Start CLI by Java and open browser through CLI.
Call the web application by url on your page.

chrome.extension.getViews() and Extension Options page

If I open a new tab and navigate to chrome-extension://{ext_id}/options.html by typing directly into the address bar the page shows up in the list when I do
chrome.extension.getViews({'tab'})
This is the expected behaviour.
If I [right click] on my extensions "browser_action" action and select "Options" this brings up a new tab with chrome-extension://{ext_id}/options.html as the URL and it shows up in the list when I do
chrome.extension.getViews({'tab'})
Again, this is the expected behavior.
If I click a link on my extensions popup, that navigates to the options page, this opens up a new tab and navigates me to chrome-extension://{ext_id}/options.html. This is the expected behavior.
BUT, there is always a but, for some reason this page does NOT show up in
chrome.extension.getViews({'tab'})
Even though it is obviously within the context and protocol of the extension. I just don't know what the difference between the FIRST and the LAST scenario is. If anything I would expect the first scenario to fail since the user is manually navigating there, rather than a extensions own popup navigating to the extensions own options page.
I have tried using both
<a href="options.html" target="_blank">
/* and */
<a id="options" target="_blank">
<script>
document.getElementById('options').href = chrome.extension.getURL('options.html');
</script>
/* This correctly sets the href as chrome-extension://{ext_id}/options.html */
but again the same problem. The extension still runs all its Javascript correctly. I still am able to use chrome.extension functionality correctly. Just the page is not showing up within getViews. I suspect it is a Sandboxing issue, but I can't understand it working for all other situations expect one.
Does anyone know how to either get it to work correctly? or open up the page in a different manner so it will work?
PS: I do not wish to open up the options page within the popup window. I have tested this, and it STILL does not list the page within the getViews but I presume this is because it is no longer a 'tab' but a 'popup'.. But again, its not the behavior I wish.
If it looks like a bug and feels like a bug, then it is probably a bug. In the future, if you think that you're experiencing a bug, don't hesitate reporting it on Chromium's bug tracker at http://crbug.com/new.
I have reported your bug as https://code.google.com/p/chromium/issues/detail?id=341459.
A work-around to get your extension page opened from the popup window to show up in chrome.extensions.getView({type: 'tab'}) is to open the tab using chrome.tabs.create:
chrome.tabs.create({
url: 'options.html'
});

Possible to run Javascript from address bar (bookmarklet) within Google Chrome's settings panel?

I would like to make a bookmarklet to open google chrome's settings panel and clear my cache with a single click.
For a while now, Ive had a bookmark that opens chrome's settings panel with the 'clear cache' setting already selected. After clicking the bookmark (normally opening it in a new tab) I have to then opent the tab and submit the form. However, when developing this is a task I have to do quite often and these several repeated steps just seem unnecessary.
This link opens the page to clear one's cache (obviously for Chrome users only): chrome://chrome/settings/clearBrowserData#cache
I recently discovered bookmarklets and thought it would be a good way to accomplish the task of clearing my cache with a single click. However, I've discovered that putting even a basic javascript sample in the address bar when on the settings page (linked above) fails to work.
For example, this works in the address bar on any given page, but not from the chrome settings page:
javascript:alert('hello stackoverflow');
Is there a way to execute javascript from the chrome settings page? Are there other options? Im looking for any route to achieve this goal and would love to learn something along the way, even if it means doing some evil. :)
add a bookmark:
javascript:document.write('<form onsubmit="window.open(\'javascript:\'+js_line.value, \'target\');return false;">javascript:<input type=text name=js_line style="width:90%;"/></form><iframe src="" name="target" style="width:100%;height:90%;"/>');
What you want might not be fully possible through a bookmarklet, but it's certainly possible with a Chrome App. There is an app Clear Cache already. I find it pretty useful.

Website wont show on IE once I activate scripts. Everything is missing except for the background

So, I've been creating a site based off a template. The site used to work on IE, but I'm afraid that I have made changes since then that causes everything to go haywire. When first visiting the site my grids and alignments are all off and most of the javascript doesnt work. When I activate scripts and ActiveX all of the elements of the site are invisible except for the background. Though, I can still see the source in this instance.
The site (for now) is: http://www.escroft.com/index(main).html
If the site is not displaying when you turn scripts on, you probably have a script error. Open your developer tools with F12, and reload the page; the console should show you what errors you have, and then you're on your way to fixing them.

Categories