Port returned by chrome.runtime.connectNative(), name cannot be set

207 views
Skip to first unread message

hujunhu...@gmail.com

unread,
Jan 16, 2019, 10:52:01 PM1/16/19
to Chromium Extensions
Hi guys, 
I developed my chrome extension that uses a native message host. In eventPage.js, I connect to local host as follow:
port = chrome.runtime.connectNative(msg.host);

After i get the port, I need to set its name to a special string as "port1" to mark it. My code is as follow:
port.name = "port1";

This works ok in most cases, but it does not work in follow case:
windows 7 + Chrome Version 72.0.3626.53(Offical Build) beta(64-bit).
After I set port.name, its still empty. It seems that port is readonly.

Why this happen? Is it a bug for this version of Chrome?

PhistucK

unread,
Jan 17, 2019, 2:25:26 PM1/17/19
to hujunhu...@gmail.com, Chromium Extensions
Generally, it is not a good idea to set properties of objects that are not defined by you. The behavior is undefined.
Does it have a name before you try to set it and you just want to change it and because connectNative does not let you (which seems like either a Chrome bug, or wrong documentation), you chose this way?
Or does it have an empty name?

PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/d04e9df0-f716-4c75-9e6a-35688c8285d0%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

hujunhu...@gmail.com

unread,
Jan 17, 2019, 8:05:56 PM1/17/19
to Chromium Extensions, hujunhu...@gmail.com

Thanks for replay.

 

Before I set it, port.name is an empty string. As I need to identify different port, so I want to set a name for each port.


Is there any official document that show the name cannot be set by user?

I just want to know why it cannot be setted.



On Friday, January 18, 2019 at 3:25:26 AM UTC+8, PhistucK wrote:
Generally, it is not a good idea to set properties of objects that are not defined by you. The behavior is undefined.
Does it have a name before you try to set it and you just want to change it and because connectNative does not let you (which seems like either a Chrome bug, or wrong documentation), you chose this way?
Or does it have an empty name?

PhistucK


On Thu, Jan 17, 2019 at 5:52 AM <hujunhu...@gmail.com> wrote:
Hi guys, 
I developed my chrome extension that uses a native message host. In eventPage.js, I connect to local host as follow:
port = chrome.runtime.connectNative(msg.host);

After i get the port, I need to set its name to a special string as "port1" to mark it. My code is as follow:
port.name = "port1";

This works ok in most cases, but it does not work in follow case:
windows 7 + Chrome Version 72.0.3626.53(Offical Build) beta(64-bit).
After I set port.name, its still empty. It seems that port is readonly.

Why this happen? Is it a bug for this version of Chrome?

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

PhistucK

unread,
Jan 18, 2019, 7:45:56 AM1/18/19
to hujunhu...@gmail.com, Chromium Extensions
I do not think there is an official documentation that says so, but changing properties of object not defined by you is not guaranteed not to have bad side effects, or to even work (a property can be defined as read only and the JavaScript engine will not let you change it).
Naming a native connection sounds like a reasonable feature request, just like you can name non-native connections (according to the documentation, I have not tried it myself) using a parameter on connect.

Generally, for feature requests, you can search crbug.com for an existing issue for this feature request and star it. If you cannot find one, you can use the "New issue" link at crbug.com to file a new one.
(If you do find one, do not add comments like "+1" or "me, too", it only hinders the development and it does not make the engineers implement the feature more quickly.)

PhistucK


On Fri, Jan 18, 2019 at 3:06 AM <hujunhu...@gmail.com> wrote:

Thanks for replay.

 

Before I set it, port.name is an empty string. As I need to identify different port, so I want to set a name for each port.


Is there any official document that show the name cannot be set by user?

I just want to know why it cannot be setted.



On Friday, January 18, 2019 at 3:25:26 AM UTC+8, PhistucK wrote:
Generally, it is not a good idea to set properties of objects that are not defined by you. The behavior is undefined.
Does it have a name before you try to set it and you just want to change it and because connectNative does not let you (which seems like either a Chrome bug, or wrong documentation), you chose this way?
Or does it have an empty name?

PhistucK


On Thu, Jan 17, 2019 at 5:52 AM <hujunhu...@gmail.com> wrote:
Hi guys, 
I developed my chrome extension that uses a native message host. In eventPage.js, I connect to local host as follow:
port = chrome.runtime.connectNative(msg.host);

After i get the port, I need to set its name to a special string as "port1" to mark it. My code is as follow:
port.name = "port1";

This works ok in most cases, but it does not work in follow case:
windows 7 + Chrome Version 72.0.3626.53(Offical Build) beta(64-bit).
After I set port.name, its still empty. It seems that port is readonly.

Why this happen? Is it a bug for this version of Chrome?

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
Reply all
Reply to author
Forward
0 new messages