w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Chrome extension: can't get message passing to work between background script and content script
From onMessage documentation. This function becomes invalid when the event listener returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end until sendResponse is called). So your code should look like chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { console.log(sender.tab ? "from a content script:" + sender.tab.url : "from the extension"); if (request.greeting == "hello") { sendResponse({farewell: "goodbye"}); return true; } });

Categories : Javascript

sendMessage from background script to content script in app fails
There's not such a thing called "Content scripts" in a Chrome app. Your manifest file looks like a mixture of a Chrome extension. Open chrome://extensions/, enable developer mode, and you would see a warning that the "background" and "tabs" permissions are invalid for a Chrome app. If you're implementing a Chrome app, just use chrome.runtime.sendMessage and chrome.runtime.onMessage. These messages can be send from and to your event page and the main page. For example: // event page (aka background page) chrome.app.runtime.onLaunched.addListener(function() { chrome.app.window.create('main.html'); }); // Later, when you want to notify the app window chrome.runtime.sendMessage(" ... any message ... "); <!-- main.html --> <script src="main.js"></script> //

Categories : Google Chrome

hover state background color lost after javascript script execution
As @DomDay noted in the comment, jQuery .animate() uses inline styles that override your CSS rules, so one solution would be to remove the inline statement when you revert the color to the original one like this: $(anchorRef).animate({'backgroundColor': 'rgb(25, 25, 25)'},function(){ $(this).removeAttr('style'); }); Working fiddle

Categories : Jquery

detect if Chrome extension content script has been injected / content script include guard
Implementing an include guard is extremely easy: (function() { if (window.hasRun) return; window.hasRun = true; // Rest of code })(); If you want to programatically inject a content script, consider using one of the webNavigation events (e.g. onCommitted) instead of chrome.tabs.onUpdated. Unlike the tabs events, the webNavigation events are also triggered for navigation within frames, and offer a way to declare an URL filter in advance.

Categories : Javascript

Chrome extension : error when sending message back from injected script to background script
I think my issue was fixed by chrome.tabs.sendMessage(tabId, {action: 'test'}, Note, I incorrectly use msg instead of action in above question. Also, I do not use the third parameter sendResponse to avoid full-duplex communication I simply post another message from content script back to background page. From content script, send message to background page using: function SendMessageToBackgroundPage(data) { chrome.runtime.sendMessage({ action: 'kungfu', source: 'panda' }); } Catch it inside background page using: chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { switch (request.action) { case 'kungfu': alert(request.source); } });

Categories : Javascript

Refused to load the script because it violates the following Content Security Policy directive: "script-src 'self'
If you build a packaged app, you can not load external script. Your application must embed every scripts, styles or images. Check this link to ensure you are following chrome app CSP rules: https://developer.chrome.com/extensions/contentSecurityPolicy

Categories : Google Chrome

No inlined script, still getting "Refused due to Content Security Policy directive: "script-src 'self'"
I had indeed messed things up a bit, although the reasons were a bit unclear. Turns out the culprit was "BANNER ". Chrome defines the javascript:void(0) call as an inlined script call. Switching the href to '#' removed the error message. The reason no tab was being opened was that attempts were made to add behaviour to components being created asynchronously in the (ajax) method getJSON(), which had not yet finished at that point. A quick move of the loop solved the issue, and things now work as expected.

Categories : Javascript

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'"
I also faced such type of problem when working with LinkedIn oAuth API. I was using linkedIn API with following settings for cordova config.xml <access origin="*" launch-external="yes"/> <allow-navigation href="*" /> Meta Tag was <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> Script <script type="text/javascript" src="http://platform.linkedin.com/in.js"></script> When i run the application on emulator its giving Fixed Problem to add uri into meta tag http://platform.linkedin.com like <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' http:

Categories : Google Chrome

Remote script as content script in Chrome extension
$.getScript defaults to injecting a <script> element to load scripts from a different origin. Consequently, the code runs in the context of the page, not the content script (see also). If you really want to use jQuery to get the script, replace $.getScript("https://mysite.com/myremotescript.js", function(){ }); with the following (eval is used as a callback, thus it evaluates the response of the request) $.get("https://mysite.com/myremotescript.js", eval); While this works, I recommend to cache the script's response body. Then, your extension will not break if the network connection drops. And, more importantly, the user will not get a useless request for every page load. I've fleshed out this concept before, see this answer.

Categories : Jquery

App crashes in background while bluetooth connection lost for long time
i am assuming that you are on iOS 6.1 Are you handling device disconnect using the following delegate methods of CBCentralManager – centralManager:didDisconnectPeripheral:error: – centralManager:didFailToConnectPeripheral:error: also i suspect there is no device discovery when in background, so you might have to handle that logic in your code

Categories : Iphone

Would like to run a background PHP script from the main PHP script
shell_exec() is just like sitting at a command prompt and typing the string value and pressing return. You can't just type "test.php" and have it fire, you need to run PHP, and point it to your php file. Depending on how you have php installed, you maybe able to simple change it to shell_exec('php test.php'); or you may have to provide a path to PHP like shell_exec('C:phpinphp.exe test.php');. The path will depend on your environment. In the code you show, if you're just sending a single email, that shouldn't take more than a few seconds so I wouldn't even go down this route. But I don't think this is the end result of your code, and just a sample.

Categories : PHP

Chrome Extension API: chrome.tabs.captureVisibleTab on Background Page to Content Script
Use chrome.tabs.sendMessage background page: chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { chrome.tabs.captureVisibleTab( null, {}, function(dataUrl) { sendResponse({imgSrc:dataUrl}); } ); //remember that captureVisibleTab() is a statement return true; } ); content script chrome.runtime.sendMessage({msg: "capture"}, function(response) { console.log(response.dataUrl); });

Categories : Javascript

lost google apps script project
if you truncate your app url before "exec" and replace with "edit" you get this url : https://script.google.com/macros/s/AKfycbyyPyHTQEiklppiU3xyJxvuCZZLLBdY-C64We4W_YlL2amWincl/edit that should work ;-) Edit : you could also simply use the drive's search tool since it searches for any string inside your documents : search for 'Hello world' and it will find all occurrences of this string, including your script...

Categories : Google Apps Script

Bash script to wait for gnome-terminal to finish before continuing script, only works for first instance of script
#!/bin/bash date bash -c "sleep 7" & bash -c "sleep 5" & wait date As you can see while running this script, both sleep commands will run in parallel, but main thread stalls, while they are running. Sat. Jule 27 01:11:49 2013 Sat. Jule 27 01:11:56 2013 Replace sleep 7 with expect launchneuron.exp and sleep 5 with expect launchmpj.exp and add your plot commands after calling "wait": echo "Simulation Complete" ...(your code to plot results)

Categories : Bash

PowerShell - script 1 calls script 2 - how to return value from script 2 to script 1
You could make use of ProcessStartInfo and Process which would allow you to read the StandardOutput. Here's an example of what you might do: $startInfo = New-Object System.Diagnostics.ProcessStartInfo $startInfo.FileName = "powershell.exe" $startInfo.Arguments = "C:scriptscript2.ps1" $startInfo.RedirectStandardOutput = $true $startInfo.UseShellExecute = $false $startInfo.CreateNoWindow = $false $startInfo.Username = "DOMAINUsername" $startInfo.Password = $password $process = New-Object System.Diagnostics.Process $process.StartInfo = $startInfo $process.Start() | Out-Null $standardOut = $process.StandardOutput.ReadToEnd() $process.WaitForExit() # $standardOut should contain the results of "C:scriptscript2.ps1" $standardOut

Categories : Powershell

Newly entered Data lost in C#.net when server connection has lost on local network
Check the code and accepted answer to the following question. It might give you a better solution to what you want to achieve In C# what is the best way to determine if a database is up and running?

Categories : C#

Powershell start-process script calls a second script - how to make one script only
Windows does not allow a process to elevate while running. There are some tricks but in one way or another they will spawn a new process with the elevated rights. See here for more info. So the easiest way for PowerShell is still using one script to Start-Process the other script elevated.

Categories : Powershell

Google Apps Script Spreadsheets - Assign script to image from a script
This would be a cool feature, but here is a possible workaround, it might even offer more functionality. You can build a UI using Google API. More detailes here. The UI allows you to create side bars/menus/etc. You could even create floating dialog windows. Using AbsolutePanel, you can even choose where the dialogue shows up.

Categories : Google Apps Script

unable to access variable declared in ksh script to csh script using shell script
The ksh script is not doing what you think it is doing when used by ksh; it sets $1 first to MyUser=root and then MyPassword=shroot. However, when you source it from your C shell script, because the syntax is compatible with C shell (checked with tcsh), you would set the two variables. If you sourced the script from a Bourne-shell derivative, the exit at the end of the ksh script would cause the shell to exit; it does not seem to cause the C shell to exit. So, what you've got is a weird hybrid. Normally, you stick to one language and use it exclusively. Where you need to use another shell, you can do so, but you simply run the script written for the other shell. You can communicate to the other script with environment variables. You don't normally try writing sourceable code that ca

Categories : Shell

How to allow cross domain content script on Firefox add-on without firing mixed content blocking errors
Specifying that permission will cause the Sandbox (worker in SDK internal terms, content script in documentation) to simply get a new XMLHttpRequest constructor, that has more than one principal (or "origin", if you like). This will only change how to same-origin-policy is evaluated, but not how security in general and mixed-content policies in particular are implemented. That is: You still cannot do a https to http XHR, as you noticed. There is no work around you can use in your content script. You could however message your main script to do the request and pass the result back (again via message passing) to the content script. Please file a bug. At the very least this limitation should be documented. Personally, I wouldn't be in favor of lifting it. Mixed-content is a security issue,

Categories : Javascript

Heroku and NodeJs - MySql Connection lost: The server closed the connection
You already seem to know what is happening; the MySQL server is closing the connection. Many database services, including ClearDB, to do this (ie, close inactive connections). You're going to have to detect the disconnect event, and recreate the connection. There are instructions in the node-mysql documentation for doing this.

Categories : Mysql

chrome extension use the same socket.io connection under background page and content scripts
I tried to write a socket.io client in content script which will send message to background page when socket.io server send "hello" request. Content Script: var socket = io.connect('http://localhost:1337'); socket.on("hello",function(data){ console.log(data.text); chrome.runtime.sendMessage({msg:"socket",text:data.text},function(response){}); }); Background page: chrome.runtime.onMessage.addListener( function(request,sender,senderResponse){ if(request.msg==="socket"){ console.log("receive from socket server: "+request.text); } } ); Server side: var app = require('http').createServer(handler).listen(1337); var io = require('socket.io').listen(app); function handler(req,res){ console.log(req.url); res.writeHead(200, {'Content-Type'

Categories : Javascript

Displaying error messages on the console when running an executable file inside a Perl script
Huh? A seg fault doesn't cause any output. You can check the error yourself, though: die "Can't launch child: $! " if $? == -1; die "Child killed by signal ".($? & 0x7F)." " if $? & 0x7F; die "Child exited with error ".($? >> 8)." " if $? >> 8;

Categories : Perl

Basic calculator script in UNIX - Want to make error messages disappear if no variables are entered
From the bash manual: getopts can report errors in two ways. If the first character of optstring is a colon, silent error reporting is used. In normal operation diagnostic messages are printed when invalid options or missing option arguments are encountered. If the variable OPTERR is set to 0, no error messages will be displayed, even if the first character of optstring is not a colon. Since you tag the question with Unix and don't mention bash, you may or may not be so lucky, but the answer is to read the manual page carefully.

Categories : Unix

How to catch connection lost error on open socket connection?
public static boolean isNetworkAvailable(Context context ,DialogInterface.OnDismissListener dismissListener, Boolean endActivity){ ConnectivityManager conMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info= conMgr.getActiveNetworkInfo(); boolean isNetworkAvailable=false; if(info != null && info.isConnected()) { isNetworkAvailable=true; // Log.e("NetworkInfo","Connected State"); } else{ isNetworkAvailable=false; alertNetworkConnection(context,dismissListener,endActivity); // Log.e("NetworkInfo","Not Connected state"); } return isNetworkAvailable; }

Categories : Android

Node.js + setInterval = Connection lost: The server closed the connection
Looks like you're keeping an open connection to a remote MySQL server. The remote server is closing the connection after 8 hours of idle connection. So you have two options. Either you send a keepalive request or you disconnect after your initial request and then open the connection again when timer initiates the next event. Keepalive If you want to send a keepalive request, simply setup a select 1 on an interval timer. select 1 is just a simple query that will cause MySQL to return a result of 1 and reset the MySQL server's connection timeout. It would look something like this. function keepalive() { connection.query('select 1', [], function(err, result) { if(err) return console.log(err); // Successul keepalive }); } setInterval(keepalive, 1000*60*5); Pooling Howeve

Categories : Javascript

Need a script to keep web page from dropping connection
It kinda depends on the app you're trying to stay connected to, but if you go with javascript, you can set up a timeInterval and have it make an ajax call to one of the web app's exposed api urls. The url and parameters of the ajax call really depend on the web app you're trying to stay connected to. setInterval(function () { $.ajax({ type: 'POST', url: "[web_app_uri]/check_in_method", data: JSON.stringify(parameters_for_method) }); }, 1000 * 60);

Categories : Javascript

Command to disconnect SSH connection from Script
Here is what you can do: kill -9 "$(ps --pid $$ -oppid=)" But I definitely suggest you not to use this way. A better solution is to get the exit code of your script and exit if needed. For example yourscript: #... ... else exit 1 fi And in your ssh connection you do: ./myscript || exit This is the correct way. Try to use it

Categories : Linux

Infobright database connection through vb script
Install MySQL Connector/ODBC 5.1 and use a connection string like the following connString = "Driver={MySQL ODBC 5.1 Driver};Server=ServerAddress;Database=DataBase;User=Username; Password=Password;"

Categories : Vbscript

When should SQL server connection be closed in a script?
You don't have to do them at all. After header('Location... you should use exit immediately. Open connections are closed when the script exits automatically. You could manually close them and use exit after that, though. You only need to worry about manually closing the connections if you're running out of connections during long-running scripts, but you may have other problems at that point.

Categories : PHP

Python script to create SSH connection
For querying EC2 resources, use the boto library. For running the ssh, use the subprocess.call (no need to end the script though). import subprocess addr = '10.20.30.40' subprocess.call([ 'ssh', addr ])

Categories : Python

Trying to use a VB Script in an SSIS package to get the Server name from a connection
For ADO.NET connections: Dim dbConn As System.Data.SqlClient.SqlConnection = Dts.Connections("ServerA").AcquireConnection(Dts.Transaction) Dim dbServer As String = dbConn.DataSource Dts.Events.FireInformation(-1, "", dbServer, String.Empty, -1, False) It yields the following in the log: [] Information: ServerNameInstanceName OleDB connections are a bit trickier -- to access the same thing in a vb script, add a reference to the .NET assembly Microsoft.SqlServer.DTSRuntimeWrap, then use the following: Dim connectionManager As ConnectionManager = Dts.Connections("oleDBConnection") Dim cmParam As Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSConnectionManagerDatabaseParameters100 cmParam = CType(connectionManager.InnerObject, Wrapper.IDTSConnectionManagerDataba

Categories : Sql Server

cannot open connection in an r script that worked previously
You have to use an escape character for the whitespace in your filepath. I would try to write the whole thing like this: C:/Users/John Broussard/Dropbox/evtHandbookProject/figuresTables/figure3Data.csv EDIT: Since this was apparently not the source of the problem, maybe the file is opened in another process? What if you copy the file and try to open the copy?

Categories : R

Pass connection string from PHP to perl script
Connecting to MySQL w/ Perl is pretty easy. Just use the same details that you're using w/ PHP, provided that both scripts are on the same server (or your DBMS accepts external connections). use DBI; $dbh = DBI->connect("dbi:mysql:databasename:localhost", 'username', 'password');

Categories : PHP

Handling my connection variable for login script use
include() does not cause the variables defined therein to become an array - they are automatically imported into the scope in which you are calling the function. Since you are not defining $config inside the include file, you're never accessing the array. So, $config = include('your_script.php') doesn't do what you likely think it does. You should update the function as follows (and change the array definition inside db_config.php to define $host, $username, $password and $dbname). function openDB() { include("/assets/configs/db_config.php"); $conn = mysqli_connect($host, $username, $password, $dbname); // 1. Create a database connection if(!$conn) { $this->error_msg = "connection error could not connect to the database:! "; return false;

Categories : PHP

Invoke python script from another python script and set execution directory of the executed script
You could use cwd parameter, to run scriptB in its directory: import os from subprocess import check_call check_call([scriptB], cwd=os.path.dirname(scriptB))

Categories : Python

Errors For Background Script
the ipn listener is triggered by an arbitrary transaction sobeit incomplete, invalid etc. in the ipn listener itself you can specify what should be handled whether it be error logging or even mailing the error to a specified email address. I have implemented the ipn handler to update database values on a valid transaction

Categories : PHP

Run PHP Script in Background(Without Using Cron)
There are a few options here: You can fork a separate PHP process with pcntl_fork (http://php.net/manual/en/function.pcntl-fork.php) You can use a cronjob to check for unsent modifications which you do not want to (you failed to mention WHY, this is why I mention it) You can use a job queue system for it. By far the best solution but takes some time to get started. Gearman is the one I have experience with and that works like a charm.

Categories : PHP

setInteval in background script
According to the chrome documentation you should use the alarms API instead. I don't know if it will solve the issue but it's definitively worth trying! I quote: If your extension uses window.setTimeout() or window.setInterval(), switch to using the alarms API instead. DOM-based timers won't be honoured if the event page shuts down. http://developer.chrome.com/extensions/event_pages.html => http://developer.chrome.com/extensions/alarms.html

Categories : Javascript

Does the execution of a PHP script halts when the connection wih the user is slow?
No. The PHP processor will execute all php-parts of the HTML file and only after he has finished will start sending the user the complete HTML data. But you can, if you want, send some HTML data already while the PHP processor is still processing PHP with ob_flush(). Then your script will run until the time limit is reached. To use ob_flush() you have to initialize it first: ob_start(). Then you can send the buffered data to the user with the desired ob_-function.

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.