How to setTitle, containing words and variable? - google-chrome-extension

I want to setBadge and setTitle like
chrome.browserAction.setBadgeText({text: String(badgeText)});
chrome.browserAction.setTitle({text: "The number "+currentDomain+ "is "+ String(badgeText)});
chrome.browserAction.setBadgeBackgroundColor({ color: '#1d2554' });
But in the title remains the title, which is set in the manifest, and the badge color becomes default blue. As error i'm getting
Uncaught TypeError: Error in invocation of browserAction.setTitle(object details, optional function callback):
Error at parameter 'details': Unexpected property: 'text'.
What i'm doing wrong? What is the correct syntax for this?
PS: Existence of default_title in the manifest doesn't play a role - if it isn't set, the title shows the name from manifest, but not the title i set in background.js.

It should be title instead of text, like:
chrome.browserAction.setTitle({title: "The number "+currentDomain+ "is "+ String(badgeText)});
https://developer.chrome.com/extensions/browserAction#method-setTitle
Also you might want to make it more readable by using template literals, so it would be:
{title: `The number ${currentDomain} is ${String(badgeText)}`}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Related

"This JSX tag's 'children' prop expects a single child of type 'ReactNode'" error when inserting JS

So I have this piece that based on the showHistory boolean should show a piece of text.
{props.showHistory && <Typography variant="body1">Your previous score was: </Typography>}
But when I want to add a variable like this:
{props.showHistory && <Typography variant="body1">Your previous score was: {props.lastScore} </Typography>}
It gives me the error "This JSX tag's 'children' prop expects a single child of type 'ReactNode', but multiple children were provided.ts(2746)". I could come up with a work-around I think, but I want to understand what exactly goes wrong here and how to fix it.

How to remove text from a field

In the SO Invoice report, I add a link from ARTran to FSAppointment. This is done in order to include FSappointment.LongDescr in the report. A request, is to remove the text 'Internal Notes' PLUS all text following the string. I notice a red error message printed in the report output, in the cases where 'Internal Notes' string is not included in LongDescr. I tried several permutations but have not found a resolution.
Here is my formula
=IIf(InStr([FSAppointment.DescriptionAsPlainText],'Internal Notes')>0,
Left( [FSAppointment.DescriptionAsPlainText], InStr([FSAppointment.DescriptionAsPlainText],'Internal Notes') )
,[FSAppointment.DescriptionAsPlainText])
Note that I created a non-bound field DescriptionAsPlainText, in order to apply pretty formatting, for LongDescr field.
Here is the error message:
An error has occurred while the Left(Identifier(FSAppointment.DescriptionAsPlainText), InStr(Identifier(FSAppointment.DescriptionAsPlainText), Const(Internal Notes))) function was being executed:
'Length cannot be less than zero.
Parameter name: length'
I think your code fails if the value of [FSAppointment.DescriptionAsPlainText] is null. Add an IIF([FSAppointment.DescriptionAsPlainText]=null, clause around your existing code to exit in case of null.

How would I isolate a string between two strings in DiscordJS?

I've currently been using this script:
var portion = body.substring(
str.lastIndexOf('ID Background',") + 1,
str.lastIndexOf('ID Theme',")
);
"Body" is the input, "Portion" being the output.
I'm trying to isolate text between the words strings "ID Background" and "ID Theme"
Example:
ID Background
Background information Background information Background information Background information
ID Theme
Theme information Theme information Theme information Theme information Theme information
...Et Cetera.
Expected Output:
Background information Background information Background information
Current Output:
undefined
I cannot figure out why this script is not working. I'm using this for a Discord bot (Discord.JS)
You should use RegExp capturing groups ()
// objective: get everything in between 'start' and 'end'
const str = 'start hello how was your day end';
// capture everything in between the two words in parentheses
console.log(str.match(/start (.*) end/)[1]);
Since you're example uses line breaks, which the special character . doesn't cover, you should use [\s\S] (\s is whitespace, and \S is anything but whitespace. Together, they cover everything. Also, use optional chaining ? so that your code doesn't throw a TypeError if no match is found.
var portion = body.match(/ID Background *([\s\S]*) *ID Theme/)?.[1];
if (!portion)
// no match found...

Watir-webdriver:How to read tooltip text

I am writing a script to set verify tool-tip for label control. I am using
$browser.label(:text,"Help").hover
$browser.text.include?("Hint Text").should == true
When I execute this, tool tip is displayed on browser, but I am not able to assert the tool-tip.
Is there any other way to do this?
You can check the title attribute of an element using the title method.
Assuming that the element is:
<label title="Hint Text">Help</label>
You can get the title attribute value:
$browser.label(:text => "Help").title
#=> "Hint Text"
Or as a validation in a test:
$browser.label(:text => "Help").title.should eq("Hint Text")
Note that you do not need to hover over the element to check its title attribute.

In Watir, how to get the full text, from a portion of text?

I have a portion of HTML that looks similar to:
<table><tbody><tr>
<td><div> Text Goes Here </div></td>
<td> ... rest of table
There are no IDs, no Titles, no descriptors of any kind to easily identify the div that contains the text.
When an error occurs on the page, the error is inserted into the location where "Text Goes Here" is at (no text is present unless an error occurs). Each error contains the word "valid".
Examples: "The form must contain a valid name" or "Invalid date range selected"
I currently have the Watir code looking like this:
if browser.frame(:index => 0).text.includes? "valid"
msg = # need to get full text of message
return msg
else
return true
end
Is there any way to get the full text in a situation like this?
Basically: return the full text of the element that contains the text "valid" ?
Using: Watir 2.0.4 , Webdriver 0.4.1
Given the structure you provided, since divs are so often used I would be inclined to look for the table cell using a regular expression as Dave shows in his answer. Unless you have a lot of nested tables, it is more likely to return just the text you want.
Also if 'valid' may appear elsewhere then you might want to provide a slightly larger sample of the text to look for
. browser(:cell => /valid/).text
Try this
return browser.div(:text => /valid/).text
or
return browser.table.div(:text => /valid/).text
if the valid is not found, it should return nil.

Resources