Passing urls from content to background - google-chrome-extension

I'm quite new when it comes to creating extensions for Chrome and have the worst time trying to grasp concepts.
What I'm hoping to do, eventually, is create an extension which will highlight all links in a page which I currently have bookmarked.
I'm currently just trying to feel my way around, and looking to grab the links and pass them to the background page, but it doesn't seem to be working for me. When I attempt to pass a link I get nothing (or object {} and then a never-ending sea of arrows pointing to various things) If I pass something else, such as "hello", I can get that to work fine. I'd be grateful for some pointers, recommendations et al.
content:
// Get all the links on the page.
var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
console.log(links[i]);
chrome.runtime.sendMessage(links[i]);
}
It does successfully return on links from the content script.
background
var links;
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
console.log(request);
});
My background script had more in it, but it didn't seem to help in any way so I've pared it back to the most basic of code.
While I would not doubt I'll have questions beyond this, the present issue is preventing me from progressing and I've not been able to figure out what (probably simple thing) I'm doing wrong.
Thanks kindly.

Thanks! Much appreciated. I'm now moving in the right direction.
For those of you (maybe one of you) wondering, it was solved simply by adding .href to the end of links[i].
eg;
chrome.runtime.sendMessage(links[i].href);

Related

GitBook: Is it possible to create links in code blocks?

I realize that normally when you describe some code (in a GitBook or anywhere else):
var foo = bar();
you don't want to add links to it. However, for some documentation I'm writing it would be really great if I could somehow add a link inside the code:
var foo = bar(); // "bar" links to a page describing bar
Is there any way to achieve this, possibly using a GitBook plug-in, HTML instead of Markdown, or some other inconvenient technique?
I found a "poor man's" solution to the problem, but if there are any better ones I'd love to hear them.
Essentially Markdown just converts indented code in to:
<pre><code>*the code*</code></pre>
Inside a <code> tag <a> tags (links) won't work, but they do work inside a <pre>, and a <pre> by itself almost looks like code block. Of course you don't get the syntax coloring with this approach, but at least it does offer a way to add links to code examples.

Vaadin - SVG Generator, any alternative?

I have been working with Vaadin charts during this week and I found a problem that I cannot solve. I need to send several charts to a PDF generation (using iTextpdf) and I could do it using SVGGenerator. The main problem is I cannot use this solution because the final laptop doesn't allow any installation, and Phantomjs is required for SVG Generator (no add-on can be installed neither). I tried to find a different solution to convert the chart content into file or buffer that I can manage, but I think I have been reading so much posts and I am not able to distinguish the solution.
So, I will try to clarify basic questions first:
a) Is it possible to manage SVG Generator without any installation in the laptop?
b) If not, is there a different way to convert a chart into an object which class could be managed to insert it into a PDF?
I can assure you I tried to read all documentation in this forum and official Vaadin forum related to this topic but I couldn't find any solution. I don't want to seem lazy, I only want to avoid spending more time and clarify the maining pre-conditions to solve this issue.
thanks in advance for your time and help.
Kind regards,
David.
You can take a screenshot of your chart and append it to pdf:
Screenshot screenshot = new Screenshot();
screenshot.setTargetComponent(myTargetComponent);
myChartLayout.addComponent(screenshot);
//when complete
screenshot.addScreenshotListener(new ScreenshotListener() {
public void screenshotComplete(ScreenshotImage image) {
//do something
}
});
//take screenshot
screenshot.takeScreenshot();
You will not be able to render a Vaadin Chart without a web browser engine of some kind. That's what PhantomJS provides. If you have a full-blown web browser at your disposal, though, you can grab the SVG markup manually from there; it's just a bit more difficult to automate. This works in Chrome:
Open your Charts app in the browser
Open the JavaScript console (Ctrl/Cmd + Shift + J)
Type something like this: copy(document.getElementsByTagName('svg')[0].outerHTML)
Paste the contents of your clipboard to a new text file and save it as an SVG.
You don't need to install phantomjs, just bundle its binary along with your web application (Reference). I did the same thing with my Amazon AWS deployment and it works just fine.

Dreamweaver doesn't show all code hints

Example in Dreamweaver CS6:
<script src="libs/Three.js"></script>
<script>
var scene = null,
function init(){
scene = new THREE.Scene();
scene. //a few code hints show up, not all
scene.rotatation.x += 0.01; //this one exists, but code hints doesn't find it
}
function move(){
scene. //no code hints show up
}
</script>
So my questions are:
in move(), the reason code hints doesn't show up is probably because they haven't been initalized in init() yet. Is there a way to make them show up in move()?
Why doesn't the code hints show scene.rotation? How do I make it show all variables/methods?
This is not just a problem for Dreamweaver, it's the same in other web builders I've tried.
This is what I mean by code hints if you're wondering: http://i.imgur.com/IDW2ljh.jpg
Choosing a good text editor and workflow is very important and can affect your productivity a lot. I would suggest using a different text editor.
Sublime Text as amazing but for three.js code hints you will have to install plugins.
Web Storm is another great editor with intelligent hints and color coding.

Sharepoint scrollbars disabled in Chrome

On the page
https://connect.wels.net/AOM/schools/Pages/default.aspx
the scroll bars don't work (disabled) in Chrome. They are fine in other browsers. I would love to solve this. Sometimes it works in Chrome. Sometimes zooming in and out fixes it. Other times, it doesn't help.
This is answered at this site:
http://withinsharepoint.com/archives/256
The cause is in fact a timing issue around execution of a specific bit of very important onload JavaScript.
The bit that doesn’t execute (and causes a systemic issue, one of the issues it causes is the scrolling weirdness), is:
body onload="if(typeof(_spBodyOnLoadWrapper) != 'undefined'; _spBodyOnLoadWrapper();"
What this line means is basically if the page has loaded the onloadwrapper function from init.js. This onloadwrapper does a bunch of things, such as loading the ECMAScript for support SP.JS, executes page JavaScript for any onload events, and any client interactivity. So basically when this doesn’t execute pretty much no client side code from SharePoint can or will work, or any script that you have that relies on any of it. Scrolling is just the tip of the ice berg. Now for the good news, it’s easy to fix (I have a case in with Microsoft to look at including the fix in a future cumulative update).
Here's the fix that worked for me. Put this at the head of your master page. This will fix Chrome and Safari and also help your _spBodyOnLoadFunctionNames functions work.
https://gist.github.com/alirobe/4224245
via http://withinsharepoint.com/archives/256
if (jQuery.browser.webkit) {
jQuery(document).ready(function () {
var interval;
function loopCheck() {
if (typeof (_spBodyOnLoadWrapper) !== "undefined" && _spBodyOnLoadCalled == false)
_spBodyOnLoadWrapper();
else
window.clearInterval(interval);
}
// Give SP a chance..
setTimeout(function () { interval = window.setInterval(loopCheck, 30); }, 120);
});
}
That is the common problem with Chrome Browser in Sharepoint, as Sharepoint is supporting Limited Functionality to the Chrome Browser.
It also happens with the Javascript Loading order in Sharepoint page.
I cant find any solution for this till date
Refer this : https://answers.uchicago.edu/page.php?id=24860

Content scripts on prerendered pages?

Are Content Scripts (http://code.google.com/chrome/extensions/content_scripts.html) injected into prerendered pages (document.webkitVisibilityState== 'prerender') ?
I’ve been reading https://developers.google.com/chrome/whitepapers/prerender and https://developers.google.com/chrome/whitepapers/pagevisibility, and am trying to figure out how Content Scripts work with page prerendering/prefetching.
Thanks
TheZ, tomdemuyt: I’m afraid you guys are missing the point. ‘run_at’ specifies whether the content script is injected before or after the DOM is constructed.
However, I am talking about document.webkitVisibilityState, which can be ‘prerender’ (when the page is in a background/invisible tab), ‘hidden’, or ‘visible’. Note that webkitVisibilityState can transition from ‘prerender’ to ‘hidden’ or ‘visible’, or back and forth between ‘hidden’ and ‘visible’, without any changes being made to the DOM. (In order to better understand this, read the articles linked in my original post.)
I think I’ve been able to determine that content scripts ARE injected into prerendered pages. Here’s the problem, however: let’s say my content script does something that should not occur on a prerendered page. For instance, it does pageview count, or adds animation, neither of which should begin until the user is actually viewing the page. So it seems that my content script should do something like what’s shown in the code examples on https://developers.google.com/chrome/whitepapers/pagevisibility - check document.webkitVisibilityState, and also listen to the ‘webkitvisibilitychange’ event, and only do pageview count/start the animation when document.webkitVisibilityState is, or has transitioned to, ‘visible’.
I may have just answered my own question, but I just wanted to make sure that I was on the right track.
Thanks
As TheZ mentioned, you should ues the run_at setting.
Link to docs : http://code.google.com/chrome/extensions/content_scripts.html#registration

Resources