Can I tell if my Chrome Extension is running on Windows? - javascript

In my Google Chrome Extension I need to copy text onto the Clipboard, and I need to know if my extension is installed on Windows OS or not. Is it possible?
PS. If it is Windows, then I will replace end-lines with "\r\n", which makes multi-line text look better on Windows.

Two ways, at least
You can simply rely on navigator.platform
Better option is to use Chrome API: chrome.runtime.getPlatformInfo():
chrome.runtime.getPlatformInfo(function callback)
Returns information about the current platform.
In the form of a PlatformInfo object.
chrome.runtime.getPlatformInfo( function(info) {
if(info.os == "win") { /* do stuff */ }
});

Related

Distinguish between chrome and chromium using Javascript

Is it possible to distinguish Google Chrome from the open source Chromium browser using Javascript? The navigator.userAgent property seems to be identical in both browsers.
You may not want to just check for Chromium because Google Chrome's PDF plugin can also be used in Chromium (by simply copying the .dll file). In fact, I'm using it right now.
The best way is to check for the Chrome PDF plugin, using window.navigator.plugins:
var pdf = false;
for (i in window.navigator.plugins) {
if (window.navigator.plugins[i].name === "Chrome PDF Viewer") {
pdf = true;
}
}
If you want to use the filename instead of the name, it's "pdf.dll" (on Windows machines).

How can I detect if the clipboard is reachable in firefox?

For my JavaScript project I need to detect if the clipboard is reachable. Because in Firefox you need to configure an access for every site which needs it, otherwise some functions (like the execCommand with cut, copy or paste attribute) can't be executed and I need to know that.
You could try saving something into the clipboard. If it fails, you know it is not accessible.
try
{
// Use some library to save some data into the clipboard.
}
catch (ex)
{
alert("Your browser seems to block access to the clipboard.");
}
Access to the clipboard is disallowed in Chrome and Firefox per default. With pure javascript it can't be done in other browsers than Internet Explorer. You will need a Flash-shim.
You can find an article about how to achieve that crossbrowser-compatibly here.
A good library for this is Zeroclipboard.

Is it possible to monitor all network traffic in a Safari Extension?

Since the newer versions of Safari (I'm running version 5.2) seem to have removed the "Activity" viewer from the "Window" menu, I would like to write an extension to have this feature back. However, in order to do that I think that I will need to be able to see what URLs are being requested in that window/tab. For Chrome, there is a "webRequest" API that does this, but I can't seem to find what I'm looking for to do this in Safari. Would someone please tell me if this is possible, and if so, where should I look next? Thanks in advance.
So far, the most I've been able to get is using an injected start script like the one below:
function trackRequests() {
console.log(event.timeStamp + ": " + event.type, event.url, event);
}
document.addEventListener("beforeload", trackRequests, true);
However, this does not provide enough for the features I'll need for this. For example, if a URL is specified without a protocol e.g. "//example.com/file.txt" that is all this handlers sees; it doesn't know what actual protocol was used or if the request was allowed.
It appears that some people on the Apple discussion forums, MacDailyNews, and ArsTechnica have expressed a desire to have this feature back in Safari as well. Here's a link to another discussion on MacRumors.com and another.
On windows I would use Fiddler but since you appear to be using a Mac here are some alternatives:
http://alternativeto.net/software/fiddler/?platform=mac
Hope this helps!
Cheers!

Need help regards copy image to clipboard in website using ASP.Net or JavaScript?

I need a help regards copy image to clipboard in website. The image is dynamically created one.
I found two solutions
Solution 1 :
using System.Windows.Forms;
Bitmap bitmapImage ;
protected void buttonClipboard_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
MemoryStream memoryStream = new MemoryStream(imageByteArray); // Image byte array is the input
bitmapImage = (Bitmap)System.Drawing.Image.FromStream(memoryStream);
memoryStream.Flush();
memoryStream.Close();
Thread cbThread = new Thread(new ThreadStart(CopyToClipboard));
cbThread.ApartmentState = ApartmentState.STA;
cbThread.Start();
cbThread.Join();
}
[STAThread]
protected void CopyToClipboard()
{
if (bitmapImage != null)
{
//Clipboard.SetData(DataFormats.Bitmap, bitmapImage);
Clipboard.SetImage(bitmapImage);
}
}
This is working fine before publishing the website.
After publishing this won't work in any website browsers because here STAThread used.
Some websites said thread won't work in published website due to internal multi-thread handling in browsers.
Solution 2 :
<script type="text/javascript">
function CopyToClip() {
var imgControl = document.getElementById('imageContent');
imgControl.contentEditable = 'true';
var controlRange;
if (document.body.createControlRange) {
controlRange = document.body.createControlRange();
controlRange.addElement(imgControl);
controlRange.execCommand('Copy');
}
imgControl.contentEditable = 'false';
return true;
}
This java-script working fine for IE before & after publishing website. But it is not working in Chrome & Mozilla in any situation.
I need one solution for Mozilla & Chrome.
Please suggest any solution for this?
IE is the only browser that supports this method of clipboard interaction. No other browser supports placing images in the clipboard.
For text you have to go with a Flash-based solution to achieve cross-browser support. You could try ZeroClipboard.
Mozilla have a clipboard guide but it's reasonably low level, and judging by this document they are not too keen on opening up the clipboard due to security concerns. In particular on "enabling clipboard access for a website":
There is no such functionality built in to Firefox.
However, there is an interesting W3C API spec for clipboard interaction. In particular, the setData method seems promising for your use case. This SO answer gives an interesting test of the onpaste event, but unfortuantly nothing on items on to the clipboard, only retrieving them.
It doesn't really work in Firefox without the user hand editing at least one config file.
In chrome it's disabled except for extensions.
If you want cross-browser clipboard support sadly a flash widget is the only truly viable way for now.

JavaScript for Chrome extension - get Windows username

I am working on a Chrome extension, where in my JavaScript function should identify the logged in Windows username.
I want to access Windows' username within JavaScript and display it in my Chrome extension web page.
I tried following <script>, this works well in IE. Is there any equivalent way possible with the Chrome browser?
function GetUserName()
{
var wshell = new ActiveXObject("WScript.Shell");
alert(wshell.ExpandEnvironmentStrings("%USERNAME%"));
}
Please let me know any built-in method to extract the username.
You're using ActiveX which is only available in IE. In my opinion you should never be able to access information like this from within a browser (and usually can't). I doubt there is a solution which functions like you want.

Categories

Resources