How to make Google Chrome Developer tools JavaScript console Variable persistent? - javascript

Is it possible to make a JavaScript variable persistent in chrome developer tools so that it remains available in next page also. For example I want to preserve the List variable
List = fetchDetails(element)
I am working on a simple script which extracts data from a page to the List variable. What I need to do is to somehow save this variable so that when I load the next page, and extract information from that page, I am able to append the details to the previously filled list.
List2 = fetchDetails(element)
List.push(...List2)
In Summary, I need to access the List across many pages.

Related

How to show a notification if a word is present anywhere on an URL, even in pop-up

Please excuse if this is a silly question. I was trying to create a chrome extension which will read the text in a web page and notify a user by any means if it is present at page anywhere even in pop up.
I have created extension but not getting how to write logic.
If any specific word is present then that should be flagged by any means. Those specific words can be maintained in a Google sheet and extension can use that as a reference to flag.
I agree with #wOxxOm, go through the official tutorial to get a good understanding of what you're trying to accomplish and how to use the content script.
And IMO, I would use Chrome.storage api chrome storage api, if they're saved to a variable, you can then access it locally, instead of you checking google sheets or some other external site, you're just checking the stored object.

json-ld for Javascript popup window content

on our website, products details page open via a Javascript popup window.
that same product page may be opened with a direct link to that page with the popup window opened.
In the above scenario #2 my json-ld data is loaded fine and Google structured data testing tool picks up the information.
However in the most common scenario i.e. scenario #1 above the json-ld data doesn't seem to load and the product information is null.
Example - scenerio 1: http://www.beride.net/school/guincho-adventours
Example - scenerio 2: http://www.beride.net/school/guincho-adventours?course=62
I used Google Tag manager to fire up the json-ld scripts
Does anyone know I can can get the json-ld information to load in the above scenario #1?
The Structured Data Testing Tool is not 100% at coping with JavaScript including the Google Tag Manager. Either post in rendered html to the tool or look at the Structured Data report in the Google Search Consoles.
Your first example is a list of products. Googles guides indicate that you should not mark up complete entities when they are listed as summaries that link to the details. They suggest you mark up a list of links.
https://developers.google.com/search/docs/guides/mark-up-listings

Getting the javascript "document HTML DOM" info within Google Apps Script

I'm having a Google spreadsheet embedded in an (Episerver) page and the spreadsheet is editable. I also have a trigger onEdit in the sheet. When running that script 'onEdit' I'd like to get the info from current page using "document.getElementsByClassName().innerHTML" to get the context of the current situation, meaning fetching the username that is currently logged in that is displayed in the section within an element.
I'm getting the error 'document is not defined' and I got the reason. This is working just running the script as a pure javascript on the site. There is no success using GAS URLFetchApp since it not fetching the current page with the current user logged in. As I see it I have two possible options:
a) Is there anyway to use HTML DOM (document...) within Google Apps Script?
b) Can I fetch current page instead of fetching a new URL in Google Apps Script?
A) I think your only option here is to us the XML service.
B) I don't believe so, as the script is self contained, and doesn't have the ability to interact with the browser. You need to know a URL in order to fetch it.
However, you mention that part of what you'd like to do is fetch the user that is currently logged in, so perhaps you might be interested in the '.getActiveUser()' method? It might be a potential solution.

Share in-memory objects in Chrome extension content scripts?

I am new to both JavaScript and Chrome development, and am trying to create an extension that injects content/CSS in certain web pages. Simple enough, but the catch is that to do so it requires looking through a significant amount of data in local storage. From what I've read so far, the correct way to do this would be either:
Reading the required data (JSON serialized) from storage directly from the content script every time the page is visited, or
Maintaining the state in the extension background page and transferring the required data (also JSON serialized) to the content script environment using message passing.
Either of these approaches, however, would be extremely inefficient due to large amounts of data being needlessly serialized and deserialized on every page load.
So, I want to know:
Is it in any way possible to maintain a shared memory cache in Chrome that content scripts injected in all tabs can access?
If not, is an alternate approach possible where the background page listens for the chrome.tabs.onUpdated event and somehow modifies the target DOM itself?
1) I don't think this is possible. You seem to have exhausted the possibilities.
2) Content scripts are the only way to access/modify a normal tab's DOM.
1- Reading the required data (JSON serialized) from storage directly from the content script every time the page is visited.
But you have to do that every time your page is loaded which you want to avoid (I guess)
2- Maintaining the state in the extension background page and transferring the required data (also JSON serialized) to the content script environment using message passing.
The only way to make Content Scripts and Background scripts interact is via Message Passing. You are not actually looking to an alternative solution but you want to improve the process and avoid message passing each time a page is loaded.
For this, you can develop a spec. The spec states for which URLs or which Domains or based on some condition you want to get the data from Background. If your current URL/Tab agrees with spec only then pass a message to background.
Optionally, Background can also do the same and send message only if your spec is followed. Moreover, when your extension is loaded, you can also cache the storage into local variable.
Use Chrome Storage API to listen for changes in storage and update your local data copy accordingly.
You can also look at this code written by me using the same approach.

Printing Reporting Services in a page throught Javascript

I Have a PerformancePoint Server 2007 Dashboard in a Sharepoint 2007 page.
In my Sharepoint page, there's 2 Filters who get passed to the Report, and I need to print this report in the page (in another button, not the SSRS one).
So what I need is a javascript method that calls the SSRS print button, which is on a named DIV, inside a WebPartZone that only have one WebPart, a PerformancePoint Dashboard Item (don't know the exact name of the webpart).
Edit:
I've noticed that the Report, that is shown by an PerformancePoint Server webpart, is being shown by an IFrame in my Sharepoint Page.
Edit2:
Due to my architecture the reporting services Iframe is on another server, causing Access Denied when accessing through javascript.
So the question in the way I wanted is not answerable anymore, however I'll try to answer the question directly inside the reporting services, just to keep the question answer accurate.
The onclick event for the print button is document.getElementById('ReportViewerControl').ClientController.LoadPrintControl();return false;, however I was unsuccessful in just adding that to another link outside of the report viewer. That makes sense, since you can have multiple reports on a page and there's one print button for each.
Maybe you can try forcing a click of the print button?
document.getElementById('ReportViewerControl_ctl01_ctl07_ctl00_ctl00').onclick();
in my document, anyway.
Solved it:
Since the SSRS was inside an Iframe of my Sharepoint i had to look inside the Iframe
(this only works when the Iframe access the same server of the webpage currently accessed or else we will get a access denied in javascript and fail silently)
I used JQuery to make things simpler and used IE 8 to lookup the nodes (since PerformancePoint Server 2007 doesn't appear in Firefox)
Nathan's javascript helped me alot, I've checked the button html structure and find that it's a table that handle's the click and the table has a attribute called title with a value called Print (note the uppercase on the firt letter), so I written this little JQuery Javascript to solve this.
$('iframe').contents().find('table[title="Print"]').click();
remembering that this won't help me, because in my case the SSRS is hosted on another server, and therefore it's not accessible throught javascript, I've just completed the answer to help other people in this situation.

Categories