How to keep variables in background.js - google-chrome-extension

I'm creating a chrome extension and came up with a question. That is how can I keep the variables in background.js. What "keep" means here is that my variables in backgrund.js seems re-initialized and previous data stored in corresponding variables is lost.
I try to use chrome.runtime.getBackgroundPage().xxx to get the variable named xxx but the value of xxx is lost sometimes.
In manifest.json I set the background.persisitent to false. Is this the root cause ?

Related

Is there a way to access a root level variable in a module?

I have a root level variable, whose value is set at run time via a tfvar file. The tfvar file used and the var value can vary. Now I want to use this variable inside a module, the terraform way to do this is to set it up as a module variable and pass the root var when creating the module.
Except, I have this module used in our infrastructure several hundred times. Is repeating this variable 100s of times the only way to do this? Can the module access root namespace to grab the variable value?
I'm half tempted to use an external data script in the module to fetch the value instead, except, I wont know which tfvars file will be in effect at runtime..
Unfortunately, the only Terraform supported way is to pass the value into the module as a variable. Terraform has made me a copy/paste expert.
The only other approach that comes to mind that Terraform supports is making creative use of the External Data Source.

Chrome DevTools error: "Failed to save to temp variable."

I am using Node Monkey to debug my NodeJS app.
It happens frequently that when I click "Store as Global Variable" in my Chrome Console it says "Failed to save to temp variable."
console.log({why:'dont', you:'work?'})
It happens also in this jsfiddle
1) Am I doing something wrong?
2) Why this happens?
Chrome: 50.0.2661.102 (64-bit)
OSX El Capitan 10.11.4
I can see two reasons why Store As Global Variable wouldn't work:
1. Wrong Console Context Selected
This is arguably a Chrome bug, but you can only store an object as a global if the console is set to the same context as the code that logged the object.
In practice this means you might need to select the correct IFrame or web worker.
For example, on jsFiddle:
In the normal jsFiddle editor page context I'm getting an error. But it works if I change the context to the contents of the fiddle itself:
2. Garbage Collection
In order for Chrome to give you a reference to the object the object still has to be in memory. If that isn't the case it can only throw an error.
However, I'm pretty sure that being shown in the console forces V8 to keep a reference to the value.
You need to create the object in the Console itself, as the reference to the object needs to be maintained by Chrome. Just put the following into the console instead:
{why:'dont', you:'work?'}
If you check out this revision where the feature was added, it says:
Adding ability to access objects from printed ObjectPropertySections
(console, scopes pane and etc.).
The problem, based on my understanding, is that console.log is outputting a string representation of the object, and just using object formatters to display it nicely. The object doesn't exist anymore. When you create an object through the console itself, Chrome is storing the object itself in memory. If you have paused on a breakpoint and have locally scoped variables, these can also be stored globally because they are also in memory.
One thing you could do in your code, if you haven't got circular references is:
console.log(JSON.stringify({why:'dont', you:'work?'}));
> {"why":"dont","you":"work?"}
In the Console, copy the output and paste it into a JSON.parse call:
JSON.parse('{"why":"dont","you":"work?"}');
> Object {why: "dont", you: "work?"}
The variable exists now in memory so you can store it.
press Ctrl+Shift+C and select any element inside the frame that prints the object, then try again.
This will fix the problem.

SSIS File System Task Copy to New Excel File Name w/Date Variable Not Found

I have an SSIS File system Task to Copy an Excel template and create one with a date appended. I get the error saying "the connection is not found. This error is thrown by Connections collection when the specific connection element is not found." It's not found because I'm trying to make it!
The preceding error says "Error at File System Task: Failed to lock variable "c:\Reports\Unregistered_20150915.xlsx" for read access with error 0xC0010001 The variable cannot be found. This occurs when an attempt is made to retrieve a variable from the Variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created".
I'm new to this, and all I want to do is run a procedure nightly and put the results in a new Excel file with the date name appended to the end. My plan was to take a blank worksheet/file and copy it into a new file, then execute the procedure on the server to load into this new file. As you can see, the variable is filling in the date just fine, so I don't understand how it says the variable cannot be found.
I've used these pages for guidance, but I am taking some of this and some of that, obviously missing something in between:
Including the Date in a Filename in SSIS using an Expression
and SSIS: Export a Query Result to a File
Any suggestions, articles, or videos would be vastly appreciated.
I found the error. When I set the destination variable, I also had an expression that kept kicking the variable out and using the evaluated result, which is not the name of the variable. I guess in some way that only a newbie can, I created the variable with the expression and created an additional expression which the program was trying to use concurrently.

Use puppet database variables in manifest

I am attempting to learn puppet, and so far so good.
What I am having an issue with is using a variable that I have set for a node or group in the web console.
I created a variable called myCustomSetting, and then in a manifest:
file {/var/tmp/myfile.txt
ensure => file,
content => $::myCustomSetting,
}
When I apply the manifest with puppet apply mytest.pp, there are no errors, but the file is empty? What am I missing?
The double semi colon indicate that you wish to reach the top level scope, where you supposedly declared your variable. Check that your variable has not been declared in a local scope.

Chef: use attributes created dynamically

I have 2 recipes that belongs to the same cookbook.
The first recipe uncompress the apache-tomcat-xxx.tar.gz file in /opt/tomcat/apache-tomcat-xxx
In that first recipe I do
tomcat_folder = ls /opt/tomcat
node.default['tomcat']['home'] = "/opt/tomcat/#{tomcat_folder}"
so this attribute is created during execution of that recipe.
My second recipe needs to use that attribute value in resource like:
template node.default['tomcat']['home'] ...
directory node.default['tomcat']['home'] ...
and
ruby_block
block do
node.default['tomcat']['home'] ....
But I receive errors due to that attribute doesn't exist when it executes.
In some other resources I could make it work using lazy{…} blocks, but in those resources I don't know how to make them work.
So my question is, how shall I do to set that attribute from recipe 1 so it is able to be used from recipe 2 when they are executed?
Here you also can use lazy, but with some workaround.
template 'tomcat_home' do
path lazy { node['tomcat']['home'] }
end
directory 'tomcat_home' do
path lazy { node['tomcat']['home'] }
end
path for directory and template is a name attribute, which means, if it is not set inside the block it is taken from the name of the resource. This is how you did it before. But if you need lazy evaluation, you can set any string as the name of the resource. Just make sure, you don't create same resources with same names, but different bodies, as they will overwrite each other.
Another thing you shouldn't to read an attribute from particular precedence level (default, normal, override). Just node['tomcat']['home'] is the way to go.

Resources